Part Number Hot Search : 
B3943 74HC05PW KE82A MBRF2 1N493 OX9162 DLE30 30120
Product Description
Full Text Search
 

To Download U3741BM-M3FL Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  43051e?atpl?08/14 description the sam4cp series belongs to atmel ? smart energy portfolio. it is based on sam4c, a high performance 32-bit, dual core arm ? cortex ? -m4 risc processor embedding a prime plc [power line communication] modem. the cores are able to operate at a maximum speed of 120 mhz, featuring 1 mbyte of embedded flash, 128 kbytes of sram and on-chip cache for each core. sam4cp unique dual arm cortex-m4 architecture supports implementation of signal pro- cessing, application and communications firmware in independent partitions. sam4cp16b system-on-chip includes a prime modem, being prime [power line intelligent metering evo- lution] an open standard technology used for smart grid applications, mainly smart metering. atmel prime modem implementation includes enhanced phy layer features such as addi- tional robust modes and frequency band extension. the peripheral set includes advanced cryptographic engine, anti-tamper, floating point unit (fpu), 5x usarts, 2x uarts, 2x twis, 6 x spi, as well as 1 pwm timer, 2x three channel general-purpose 16-bit timers an rtc, a 10-bit adc, and a 46 x 5 segmented lcd controller. the sam4cp series is a scalable platform providing, alongside atmel?s industry leading sam4 standard microcontrollers, unprecedented cost structure, performance and flexibility to smart meter designers worldwide. it operates from 1.62v to 3.6v and is available in 176-pin lqfp package. sam4cp16b atmel smart power line communications device datasheet
sam4cp [datasheet] 43051e?atpl?08/14 2 1. features ? application/master core (cm4p0) ? arm cortex-m4 running at up to 120 mhz (1) ? memory protection unit (mpu) ? dsp instruction ? thumb ? -2 instruction set ? instruction and data cache controller with 2 kbytes cache memory ? memories ? 1024 kbytes of embedded flash for program code (i-code bus) and program data (d-code bus) with built-in ecc (2-bit error detection and 1-bit correction per 128 bits) ? 128 kbytes of embedded sram (sram0) for program data (system bus) ? 8 kbytes of rom with embedded boot loader routines (uart) and in-application programming (iap) routines ? co-processor (cm4p1), provides ability to separate application, communication or metrology functions ? arm cortex-m4f running at up to 120 mhz ? ieee ? 754 compliant, single precision floating-point unit (fpu) ? dsp instruction ? thumb-2 instruction set ? instruction and data cache controller with 2 kbytes cache memory ? memories ? 16 kbytes of embedded sram (sram1) for program code (i-code bus) and program data (d-code bus and system bus) ? 8 kbytes of embedded sram (sram2) for program data (system bus) ? symmetrical/asynchronous dual core architecture ? interrupt-based interprocessor communication ? asynchronous clocking ? one interrupt controller (nvic) for each core ? each peripheral irq routed to each nvic input ? cryptography ? high-performance aes 128 to 256 with various modes (gcm, cbc, ecb, cfb, cbc-mac, ctr) ? trng (up to 38 mbit/s stream, with tested diehard and fips) ? classical public key crypto accelerator and associated rom library for rsa, ecc, dsa, ecdsa ? integrity check module (icm) based on secure hash algorithm (sha1, sha224, sha256), dma assisted ? safety ? 4 physical anti-tamper detection i/o with time stamping and immediate clear of general backup registers ? security bit for device protection from jtag accesses ? shared system controller ? power supply ? embedded core and lcd voltage regulator for single supply operation ? power-on-reset (por), brownout detector (bod) and watchdog for safe operation ? low power sleep and backup modes ? clock ? 3 to 20 mhz quartz or ceramic resonator oscillators with clock failure detection ? optional low-power 32.768 khz crystal oscillator for rtc ? high precision 4/8/12 mhz factory trimmed internal rc oscillator with on-the-fly trimming capability ? one high frequency pll up to 240 mhz, one 8 mhz pll with internal 32 khz input, as source for high frequency pll ? low power slow clock internal rc oscillator as permanent clock
3 sam4cp [datasheet] 43051e?atpl?08/14 ? ultra low-power rtc with gregorian and persian calendar, waveform generation in low-power modes and clock calibration circuitry for 32.768 khz crystal frequency compensation circuitry ? up to 23 peripheral dma (pdc) channels ? shared peripherals ? one segmented lcd controller ? display capacity of 46 segments and 5 common terminals ? software selectable lcd output voltage (contrast) ? low current consumption in steady state mode ? can be used in backup mode ? up to 5 usarts with iso7816, irda ? , rs-485, spi and manchester mode ? two 2-wire uarts with one uart (uart1) supporting optical transceiver providing an electrically isolated serial communication with hand-help equipment, such as calibrators, compliant with ansi-c12.18 or iec62056-21 norms ? two 400 khz master/slave and multi-master two-wire interface (i 2 c compatible) ? one spi ? two 3-channel 16-bit timer/counter with capture, waveform, compare and pwm mode. quadrature decoder logic and 2-bit gray up/down counter for stepper motor ? 4-channel 16-bit pulse width modulator ? 32-bit real-time timer ? prime plc ? modem ? power line carrier modem for 50 hz and 60 hz mains ? 97-carriers ofdm prime compliant ? dbpsk, dqpsk, d8psk modulation schemes available ? additional enhanced modes available: dbpsk robust, dqpsk robust, named ?prime + robust? in this datasheet ? eight selectable channels between 42khz to 472khz available. only one channel can be active at a time ? baud rate selectable: 5.4 to 128.6 kbps ? four dedicated buffers for transmission/reception ? up to 124.6 db vrms injected signal against prime load ? up to 79.6 db of dynamic range in prime networks ? automatic gain control and continuous amplitude tracking in signal reception ? class d switching power amplifier control ? integrated 1.2v ldo regulator to supply analog functions ? medium access control co-processor features ? viterbi soft decoding and prime crc calculation ? 128-bit aes encryption ? channel sensing and collision pre-detection ? analog conversion block ? 8-channel, 500 ks/s, low power, 10-bit sar adc with digital averager providing 12-bit resolution at 30 ks/s ? software controlled on-chip reference ranging from 1.6v to 3.4v ? temperature sensor and backup battery voltage measurement channel
sam4cp [datasheet] 43051e?atpl?08/14 4 ? debug ? star topology ahb-ap debug access port implementation with common sw-dp / swj-dp providing higher performance than daisy-chain topology ? debug synchronization between both cores (cross triggering to/from each core for halt and run mode) ? i/o ? up to 69 i/o lines with external interrupt capability (edge or level sensitivity), schmitt trigger, internal pull- up/pull-down, debouncing, glitch filtering and on-die series resistor termination ? three parallel input/output controllers ? packages ? 176-lead lqfp, 24 x 24 mm, pitch 0.5 mm note: 1. 120 mhz: -40/+85c, vddcore = 1.2v or using internal voltage regulator. 1.1 configuration summary table 1-1 summarizes the configurations of the device family. notes: 1. using spi mode of usart. 2. one channel is reserved for internal temperature sensor, one for battery voltage measurement on vddbu. table 1-1. configuration summary feature sam4cp16b flash 1024 kbytes sram 128 + 16 + 8 kbytes package lqfp 176 number of pios 69 16-bit timer 6 ch. 16-bit pwm 4 ch. uart / usart 2/5 spi (1) 6 twi 2 10-bit adc channels (2) 7 crypto aes, cpkcc, icm (sha), trng segmented lcd 46x5 flash page size 512 flash pages 2048 flash lock region size 8192 flash lock bits 128
5 sam4cp [datasheet] 43051e?atpl?08/14 1.2 sam4cp application block diagram figure 1-1. sam4cp application block diagram sam4cp16b 20mhz crystal 115/230 vac dc/dc zero crossing mains 3v3 twi uart to usb rs485 slow clock crystal back-up battery 2 kb eeprom plc coupling plc spi1 & usart1 jtag usart0 rs485 transceiver uart0 & uart1 segs coms gpios xplained pro jtag bn / mimo uarts cmos b micro usb port lcd user leds reset fwup & tmp0 rectifier
sam4cp [datasheet] 43051e?atpl?08/14 6 2. block diagram figure 2-1. sam4cp16b 176-pin block diagram high speed ahb multilayer bus matrix 0 sam4cp arst srst vz cross intest [0:9] digital voltage regulator pdc0 pdc0 tc[3..5] tioa[3:5] tiob[3:5] tclk[3:5] usart0 uart0 twck0 twd0 twd1 urxd0 utxd0 rxd0 txd0 sck0 rts0 cts0 twck1 tiob[0:2] tclk[0:2] tioa[0:2] twi0 twi1 pdc0 pdc0 pdc0 pdc0 pdc0 rom (sam-ba cpkcl) flash 1024 kb sram 0 128 kb usart1 rxd1 txd1 sck1 rts1 cts1 usart2 rxd2 txd2 sck2 rts2 cts2 usart3 rxd3 txd3 sck3 rts3 cts3 usart4 rxd4 txd4 sck4 rts4 cts4 advref true random number generator aes pdc0 icm (sha) (integrity checker module) dma cpkcc (classical public key cryptography controller) ad[0:1] adtrg 10-bit adc ahb to apb bridge 0 sram 2 8 kb tdi tdo/traceswo tms/swdio tck/swclk jtagsel sram 1 16 kb pio com[0..4] segment lcd controller seg[3..47] asynchronous ahb to ahb bridge uart1 urxd1 utxd1 pdc1 pdc1 spi1 spi1_npcs0 spi1_miso1 spi1_mosi1 spck1 pwm[0:3] pwm interprocessor communication (ipc1) inter-processor communication (ipc0) high speed ahb multilayer bus matrix 1 serial wire and jtag debug port (sw-dp / swj-dp) n v i c cortex-m4f cm4p1 dsp fpu ahb-ap system bus n v i c dsp ahb-ap mpu icode / dcode bus icode / dcode bus system bus cortex-m4 cm4p0 timer counter a tc[0..2] timer counter b tc[3..5] ahb to apb bridge 1 instr./data cache controller 2 kb cache memory i/d bus s bus s bus master master master master master/slave master/slave master master slave/master slave/master slave slave slave slave slave slave slave slave instr./data cache controller 2 kb cache memory peripheral dma 1 peripheral dma 0 master real time timer xtal osc 32 khz supply controller backup zone reset controller backup reg (16) por rc 32 khz supp.mon pmc pio controller plla 8 mhz pllb high freq . rc osc 4/8/12 mhz xtal osc 3 - 20 mhz system controller tst pck [0:2] xin xout automatic power switch core voltage regulator lcd voltage regulator vddbu nrst fwup xin32 xout32 vddcore vddio vddpll vddin vddout vddlcd erase tmp [1:3] tmp0 rtcout0 shdn pplc seg49 vrp vrm vrc vima vipa clkout clkea clkeb pll init emit [0:11] agc [0:5] txrx [0:1] ad[3..5] p r o x y p l c c o n t r o l l e r pdc0 analog voltage regulator vddin an vddout an vddin plc vddout plc pll vddpll plc spi1_npcs[1:3] real time clock time stamping anti-tampering dual watchdog sub-system 0 sub-system 1 ecc temp. sensor pdc0 digital averager optical port
7 sam4cp [datasheet] 43051e?atpl?08/14 3. signal description table 3-1 gives details on signals names classified by peripheral. table 3-1. signal description list signal name function type active level voltage reference comments power supplies vddio see table 5-1 on page 13 power 3.0v to 3.6v vddbu power 1.6v to 3.6v vddin power 2.5v to 3.6v (1) vddlcd power 2.5v to 3.6v (2) vddout power 1.2v vddpll power 1.08v to 1.32v vddcore power 1.08v to 1.32v vddpll plc power 1.2v vddin plc power 3.0v to 3.6v vddout plc power 1.2v vddin an power 3.0v to 3.6v vddout an power 1.2v gnd power agnd power clocks, oscillators and plls xin main crystal oscillator input analog digital vddio xout main crystal oscillator output xin32 slow clock crystal oscillator input analog digital vddbu xout32 slow clock crystal oscillator output pck0 - pck2 programmable clock output output vddio clkea plc external clock input input vddio clkeb plc external clock input/output i/o vddio clkout 10mhz external clock output output vddio real time clock rtcout0 programmable rtc waveform output output vddio to use this pin, the jtag interface must be used in swd mode fwup force wake-up input input low vddbu external pull-up needed tmp0 anti-tampering input 0 input vddbu tmp1 - tmp3 anti-tampering inputs 1 to 3 input vddio shdn active low shut-down control output vddbu 0: the device is in backup mode 1: the device is running (not in backup mode) serial wire / jtag debug port - swj-dp jtagsel jtag selection input high vddbu permanent internal pull-down. (3)
sam4cp [datasheet] 43051e?atpl?08/14 8 tck/swclk test clock/serial wire clock input vddio tdi test data in input tdo/traceswo test data out / trace asynchronous data out output tms/swdio test mode select input / serial wire input/output input / i/o flash memory erase flash and nvm configuration bits erase command input high vddio reset / test nrst synchronous microcontroller reset i/o low vddio permanent internal pull-up. (3) tst test select input vddbu permanent internal pull-down. (3) arst plc asynchronous reset input low vddio permanent internal pull-up. (4) srst plc synchronous reset input low vddio permanent internal pull-up. (4) pll init plc pll initialization signal input low vddio permanent internal pull-up. (4) pplc (prime power line communications) transceiver emit0 - emit11 plc transmission ports (5) output vddio different configurations allowed depending on external topology and net behaviour agc0 - agc5 plc automatic gain control output vddio txrx0 - txrx1 plc ext. coupling txrx control output vddio vima negative differential voltage input input vddout an vipa positive differential voltage input input vddout an vrp internal reference ?plus? voltage output vddout an vrm internal reference ?minus? voltage output vddout an vrc common-mode voltage output vddout an vz cross mains zero-cross detection signal (6) input vddio permanent internal pull- down. (4) intest0 plc internal test input vddio permanent internal pull-up. (4) this pin must be connected to intest5 (pin 144). intest1 plc internal test input vddio permanent internal pull-up. (4) this pin must be connected to intest6 (pin 45). table 3-1. signal description list (continued) signal name function type active level voltage reference comments
9 sam4cp [datasheet] 43051e?atpl?08/14 intest2 plc internal test input vddio permanent internal pull-up. (4) this pin must be connected to intest7 (pin 176). intest3 plc internal test output vddio this pin must be connected to intest8 (pin 111). intest4 plc internal test output vddio this pin must be connected to intest9 (pin 20). intest5 plc internal test output vddio this pin must be connected to intest0 (pin 94). intest6 plc internal test output vddio this pin must be connected to intest1 (pin 95). intest7 plc internal test output vddio this pin must be connected to intest2 (pin 97). intest8 plc internal test input vddio this pin must be connected to intest3 (pin 99). intest9 plc internal test input vddio this pin must be connected to intest4 (pin 4). pio controller - pioa - piob - pioc pa0 - pa4, pa9 - pa31 parallel io controller a digital i/o vddio pb0 - pb29, pb31 parallel io controller b pc0 - pc9 parallel io controller c universal asynchronous receiver transceiver - uartx urxdx uart receive data input vddio analog mode for optical receiver utxdx uart transmit data output universal synchronous asynchronous receiver transmitter - usartx sckx usartx serial clock i/o vddio txdx usartx transmit data i/o rxdx usartx receive data input rtsx usartx request to send output ctsx usartx clear to send input timer/counter - tc tclkx tc channel x external clock input input vddio tioax tc channel x i/o line a i/o tiobx tc channel x i/o line b i/o table 3-1. signal description list (continued) signal name function type active level voltage reference comments
sam4cp [datasheet] 43051e?atpl?08/14 10 notes: 1. vddlcd must be inferior or equals to (vddio/vddin - 100mv) if vddlcd is powered externally. 2. see ?typical powering schematics? section for restrictions on voltage range of analog cells. 3. see table 45-5 on page 1009 . 4. see table 45-11 on page 1018 . 5. different configurations allowed depending on external topology and net behavior. 6. depending on whether an isolated or a non-isolated power supply is being used, isolation of this pin should be taken into account in the circuitry design. please refer to the reference design for further information. pulse width modulation controller - pwmc pwmx pwm waveform output for channel x output vddio serial peripheral interface - spi spi1_miso master in slave out i/o vddio spi1_mosi master out slave in i/o spi1_spck spi serial clock i/o spi1_npcs0 spi peripheral chip select 0 i/o low npcs0 is also nss for slave mode spi1_npcs1 - spi1_npcs3 spi peripheral chip select output low segmented lcd controller - slcdc com[4:0] common terminals output vddio seg49 seg[47:3] segment terminals output two-wire interface - twi twdx twix two-wire serial data i/o vddio twckx twix two-wire serial clock i/o analog advref external voltage reference for adc analog 10-bit analog-to-digital converter - adc ad0 - ad1 ad3 - ad5 analog inputs analog digital vddio adc input range limited to [0 - advref] adtrg adc trigger input fast flash programming interface - ffpi pgmen0-pgmen1 programming enabling input vddio pgmm0-pgmm3 programming mode pgmd0-pgmd15 programming data i/o pgmrdy programming ready output high pgmnvalid data direction low pgmnoe programming read input low pgmncmd programming command low table 3-1. signal description list (continued) signal name function type active level voltage reference comments
11 sam4cp [datasheet] 43051e?atpl?08/14 4. package and pinout 4.1 sam4cp package and pinout 4.1.1 176-lead lqfp package outline figure 4-1. orientation of the 176-lead lqfp package 1 44 4 5 8 8 89 132 1 33 1 76
sam4cp [datasheet] 43051e?atpl?08/14 12 4.1.2 176-lead lqfp pinout table 4-1. sam4cp 176-lead lqfp pinout 1 vddio 45 intest6 89 pa30/xout 133 pa15 2 pa2 46 tdi/pb0 90 vddio 134 pa16 3 pb6 47 nc 91 nc 135 pa17 4 intest4 48 tck/swclk/pb3 92 pa31/xin 136 vddio 5 pb7 49 tms/swdio/pb2 93 clkout 137 advref 6 pb18 50 erase/pc9 94 intest0 138 gnd 7 gnd 51 tdo/traceswo/ pb1/rtcout0 95 intest1 139 vddio 8 pb19 52 pc1 96 gnd 140 pb31/ad5 9 pb8 53 nc 97 intest2 141 pb23/ad4 10 agnd 54 nc 98 gnd 142 pb13/ad3 11 vddout an 55 nc 99 intest3 143 gnd 12 vima 56 arst 100 vddpll 144 intest5 13 vipa 57 pll init 101 pc8 145 pa4/ad1 14 vddout an 58 pc6 102 pc5 146 emit8 15 agnd 59 vddio 103 pc4 147 pa12/ad0 16 vrp 60 gnd 104 pc3 148 vddin 17 vrm 61 clkea 105 vddio 149 emit9 18 vrc 62 vddio 106 pc2 150 vddin 19 pb22 63 clkeb 107 pa29 151 emit10 20 intest9 64 vddio 108 pa28 152 vddout 21 pb25 65 vddbu 109 gnd 153 emit11 22 vddin an 66 fwup 110 pa27 154 pb21 23 pb24 67 jtagsel 111 intest8 155 pb20 24 vddcore 68 shdn 112 vddcore 156 vddio 25 agnd 69 tst 113 emit0 157 vddcore 26 pb29 70 vddpll plc 114 pa3 158 pa0 27 pb9 71 tmp0 115 pa21 159 vddout plc 28 pb10 72 gnd 116 pa22 160 txrx0 29 pb11 73 xin32 117 emit1 161 txrx1 30 vddin an 74 vddin plc 118 emit2 162 agc2 31 pb12 75 vddin plc 119 emit3 163 pb27/tmp2 32 pb14 76 xout32 120 vddio 164 agc5 33 pb15 77 gnd 121 gnd 165 vddlcd 34 pa26 78 vddout plc 122 emit4 166 agc1 35 gnd 79 gnd 123 emit5 167 agc4 36 pa25 80 nc 124 pa23 168 agc0 37 vddio 81 pb4 125 emit6 169 agc3 38 pa24 82 vddcore 126 pa9 170 pb26 39 vz cross 83 pb5 127 pa10 171 vddio 40 pa20 84 srst 128 pa11 172 pb28/tmp3 41 nc 85 pc7 129 emit7 173 pb16/tmp1 42 pa19 86 pc0 130 pa13 174 pa1 43 pa18 87 nrst 131 pa14 175 pb17 44 nc 88 vddio 132 gnd 176 intest7
13 sam4cp [datasheet] 43051e?atpl?08/14 5. power supply and power control 5.1 power supplies the sam4cp has several types of power supply pins. in most cases, a single supply scheme for all power supplies (except vddbu) is possible. figure 5-1 below shows power domains according to the different power supply pins. figure 5-1. power domains table 5-1. power supply voltage ranges power supplies ranges comments vddio 3.0v to 3.6v input/output buffers supply oscillator pads supply flash memory charge pumps supply for erase and program operations, and read operation vddbu 1.6v to 3.6v backup area power supply vddbu is automatically disconnected when vddio is present (>1.9v) vddin 2.5v to 3.6v core voltage regulator supply lcd regulator supply adc and programmable voltage reference supply vddlcd 2.5v to 3.6v lcd voltage regulator output external lcd power supply (lcd regulator not used) vddio/vddin need to be supplied when the lcd controller is used vddout 1.2v core voltage regulator output. 120ma output current vddpll 1.08v to 1.32v plla and pllb supply vddcore 1.08v to 1.32v core logic, processors, memories and analog peripherals supply vddpll plc 1.2v plc pll vddin plc 3.0v to 3.6v plc digital ldo regulator input vddout plc 1.2v plc digital ldo regulator output vddcore vddpll cortex-m4 (cm4p0) cortex-m4 (cm4p1) sram, rom flash logic peripherals (spi, usart, ?) pio controller vddio vddbu vddin lcd voltage regulator core voltage regulator vddlcd vddout input / output buffers automatic power switch charge pumps fast rc osc 4/8/12 mhz plla, pllb rc osc 32 khz xtal osc 32 khz rtc, rtt, rstc backup, reg, ... 10-bit adc, temp. sensor, voltage reference xtal osc, 3 - 20 mhz lcd analog buffers + switch array plc analog voltage regulator plc digital voltage regulator plc pll vddin an vddout an vddin plc vddout plc vddpll plc vddbu_sw vddio advref
sam4cp [datasheet] 43051e?atpl?08/14 14 separate pins are provided for gnd and agnd grounds. layout considerations should be taken into account to reduce interference. ground pins should be connected as shortly as possible to the system ground plane. 5.1.1 core voltage regulator the sam4cp embeds a core voltage regulator that is managed by the supply controller.this internal regulator is designed to supply the internal core of sam4cp. it features two operating modes: ? in normal mode, the quiescent current of the voltage regulator is less than 500 a when sourcing maximum load current, i.e. 120 ma. internal adaptive biasing adjusts the regulator quiescent current depending on the required load current. in wait mode quiescent current is only 5 a. ? in backup mode, the voltage regulator consumes less than 100 na while its output (vddout) is driven internally to gnd. the default output voltage is 1.20v and the start-up time to reach normal mode is less than 500 s. for adequate input and output power supply decoupling/bypassing, refer to the ?voltage regulator? section in the ?electrical characteristics? section of the datasheet. 5.1.2 lcd voltage regulator the sam4cp embeds an adjustable lcd voltage regulator that is managed by the supply controller. this internal regulator is designed to supply the segment lcd outputs. the lcd regulator output voltage is software selectable with 16 levels to adjust the display contrast. if not used, its output (vddlcd) can be bypassed (hi-z mode) and an external power supply can be provided onto the vddlcd pin. in this case, vddio still needs to be supplied. the lcd voltage regulator can be used in every power modes (backup, wait, sleep and active). for adequate input and output power supply decoupling/bypassing, refer to the ?voltage regulator? section in the ?electrical characteristics? section of the datasheet. 5.1.3 plc voltage regulators the sam4cp embeds two plc-dedicated voltage regulators, plc analog voltage regulator (vddin an) and plc digital voltage regulator (vddin plc). these internal regulators are designed to supply the plc peripheral block in an efficient way trying to minimize noise coupling in power supply. 5.1.4 automatic power switch the sam4cp features an automatic power switch between vddbu and vddio. when vddio is present, the backup zone power supply is powered by vddio and current consumption on vddbu is close to zero (around 100 na, typ.). switching between vddio and vddbu is transparent to the user. 5.1.5 typical powering schematics the sam4cp supports a 3.0v to 3.6v single supply operation. restrictions on this range may apply depending on enabled features. refer to the section electrical characteristics. figure 5-2 , figure 5-3 and figure 5-4 show simplified schematics of the power section. vddin an 3.0v to 3.6v plc analog ldo regulator input vddout an 1.2v plc analog ldo regulator output gnd - digital ground agnd - analog ground table 5-1. power supply voltage ranges (continued) power supplies ranges comments
15 sam4cp [datasheet] 43051e?atpl?08/14 5.1.5.1 single supply operation figure 5-2 below shows a typical power supply scheme with a single power source. vddio, vddin, vddbu, vddin an and vddin plc are derived from the main power source (typically a 3.3v regulator output) while vddcore, vddpll, vddlcd and vddpll plc are fed by the embedded regulators outputs. figure 5-2. single power supply note: 1. internal lcd voltage regulator can be disabled to save its operating current. vddlcd must then be pro- vided externally. - 10-bit adc - temp. sensor - voltage ref. automatic power switch backup region rtc, rtt and backup registers vddin core voltage regulator vddout main supply (3.0v-3.6v) vddcore vddbu vddpll lcd voltage regulator (1) vddlcd vddio main supply voltage regulator in out prime plc transceiver lcd buffers + lcd switch array vddin an plc analog voltage regulator plc digital voltage regulator vddout an adc plc vddin plc vddout plc vddpll plc
sam4cp [datasheet] 43051e?atpl?08/14 16 5.1.5.2 single supply with backup battery figure 5-3 shows a typical single power supply scheme for vddio, vddin, vddin an, vddin plc, vddcore, vddpll and vddpll plc. vddbu is supplied with a separate backup battery. in this supply scheme, the internal lcd voltage regulator can be used. note that if anti-tamper pins (tmp1 to tmp3) and the rtcout0 output have to be used in backup mode, vddio must be kept. the reference voltage of the tmp1 to tmp3 and rtcout0 pins is vddio. note that plc transceiver is not functional when working in backup mode. figure 5-3. single supply with backup battery notes: 1. example with the shdn pin used to control the main regulator enable pin. shdn defaults to vddbu at startup and when the device wakes up from a wake-up event (external pin, rtc alarm, etc.). when the device is in backup mode, shdn defaults to 0. - 10-bit adc - temp. sensor - voltage ref. automatic power switch backup region rtc, rtt and backup registers vddin core voltage regulator vddout main supply (3.0v-3.6v) vddcore vddbu vddpll lcd voltage regulator vddlcd vddio main supply voltage regulator in out prime plc transceiver lcd buffers + lcd switch array vddin an plc analog voltage regulator plc digital voltage regulator vddout an adc plc vddin plc vddout plc vddpll plc backup battery + - backup power supply (1.6v-3.6v) shutdown (shdn) (1) force wake-up (fwup) external wake-up signal on / off
17 sam4cp [datasheet] 43051e?atpl?08/14 5.1.5.3 single power supply using one main battery and lcd controller in backup mode figure 5-4 below shows a typical power supply scheme when the system needs to continue working and/or has to maintain display in backup mode when the main voltage is not present. in this power supply scheme, the sam4cp can wake up both from an internal wake-up source, such as rtt, rtc and vddio supply monitor, and from an external source, such as generic wake-up pins (wkupx), anti-tamper inputs (tmpx) or force wake-up (fwup). note that plc transceiver is not functional when working in backup mode. note: the vddio supply monitor only wakes up the device from backup mode on a negative-going vddio supply (as system alert). thus, the supply monitor cannot be used to wake up the device when the vddio supply is rising at power cycle. see the supply controller section for more information about the vddio supply monitor. figure 5-4. single power supply using battery and lcd controller in backup mode notes: 1. vddio corresponds to the following pins: 37, 64, 90, 105, 120, 139, 156 and 171. 2. vddio corresponds to the following pins: 1, 59, 62, 88 and 136. 3. internal lcd voltage regulator can be disabled to save its operating current. vddlcd must then be pro- vided externally. 4. the state output of the power switch indicates to the mcu that the main supply is back and forces the sys- tem to wake up. - 10-bit adc - temp. sensor - voltage ref. automatic power switch backup region rtc, rtt and backup registers vddin core voltage regulator vddout main supply (3.0v-3.6v) vddcore vddbu vddpll lcd voltage regulator (3) vddlcd vddio (2) main supply voltage regulator in out on/off prime plc transceiver lcd buffers + lcd switch array vddin an plc analog voltage regulator vddout an adc plc vddin plc vddout plc vddpll plc shutdown (shdn) (5) force wake-up (fwup) (4) state = 0 when main supply is off automatic power switch state + - battery generic wake-up pin (wkupx) vddio (1) plc digital voltage regulator nrst (6) to pll init
sam4cp [datasheet] 43051e?atpl?08/14 18 5. example with the shdn pin used to control the main regulator enable pin. shdn defaults to vddbu at startup and when the device wakes up from a wake-up event (external pin, rtc alarm, etc). when the device is in backup mode, shdn defaults to 0. 6. the nrst pin integrates a permanent pull-up resistor to vddio of typical 100 k ? . when used to control pll init as in the example, external design should take into account minimizing leakage currents. 5.1.5.4 wake-up, anti-tamper and rtcout0 pins in all power supply figures shown above, if generic wake-up pins other than wkup0/tmp0 are used either as a wake-up or a fast startup input, or as anti-tamper inputs, vddio must be present. this also applies to the rtcout0 pin. 5.1.5.5 general purpose io (gpio) state in low-power modes in dual power supply schemes shown in figure 5-4 , where backup or wait mode has to be used, configuration of the gpio lines is kept in the same state as before entering backup or wait mode. thus, to avoid extra current consumption on the vddio power rail, the user must configure the gpios either as an input with pull-up or pull-down enabled, or as output low or high levels corresponding to the external on-board devices. 5.1.5.6 default general purpose io (gpio) state after reset the reset state of the gpio lines after reset is given in table 11-5, ?multiplexing on pio controller a (pioa)? , table 11- 6, ?multiplexing on pio controller b (piob)? and table 11-7, ?multiplexing on pio controller c (pioc)? . for further details about the general purpose io and system lines, wake-up sources and wake-up time, and typical power consumption in different low-power modes, refer to table 5-2, ?low-power mode configuration summary? .
19 sam4cp [datasheet] 43051e?atpl?08/14 5.2 clock system as shown in figure 5-5 below, the sam4cp clock system allows single crystal operation: ? the 32 khz oscillator can be the source clock of the 8 mhz digital pll (plla). ? the 8 mhz clock can feed the high frequency pll (pllb) input. ? the output of the pllb can be used as a main clock for both cores and the peripherals. figure 5-5. sam4cp16b global clock system plla pllb and divider /2 plladiv2 pllbdiv2 management controller main clock mainck control status moscsel xin xout xin32 xout32 slck xtalsel ( supply controller) 0 1 0 1 3-20 mhz crystal or ceramic resonator oscillator embedded 4/8/12 mhz fast rc oscillator 32768 hz crystal oscillator embedded 32 khz rc oscillator srcb 1 0 clock generator slow clock power periph_clk[n] int slck mainck pllack prescaler / 1,/2,/3,/4,/8, /16,/32,/64 processor clock controller sleep mode master clock controller (pmc_mckr) peripherals clock controller (pmc_pcerx / pmc_pcr) pllbck core 0 (cm4-p0 clock system ) c o r e 0 ( c m 4 - p 0 c l o c k s y s t e m ) core 1 (cm4-p1 clock system ) c o r e 1 ( c m 4 - p 1 c l o c k s y s t e m ) pres css on/off on/off on/off periph_clk[n+1] periph_clk[n+2] slck mainck pllack prescaler divide by 1 to 16 master clock controller (pmc_mckr) pllbck cppres cpcss on/off periph_clk[m+2] int coprocessor clock cphclk where m is an index for the coprocessor system peripherals cpfclk coprocessor free running clock coprocessor systick clock cpsystick divider / 8 divider / 8 mck pmc_scer/scdr cpck= on/off where n is an index for the processor system peripherals on/off periph_clk[m] coprocessor bus master clock cpbmck processor clock hclk fclk processor free running clock processor systick clock systick processor bus master clock mck pmc_scer/scdr cpbmck= on/off coprocessor clock controller sleep mode pllb clock pllbck plla clock pllack 32 khz up to120 mhz 8 mhz
sam4cp [datasheet] 43051e?atpl?08/14 20 5.3 system state at power-up 5.3.1 device configuration after the first power-up after the fist power up, the sam4cp boots from the rom. the device configuration is defined by sam-ba ? boot program. 5.3.2 device configuration after a power cycle when booting from flash memory after a power cycle of all the power supply rails, the system peripherals, such as the flash controller, the clock generator, the power management controller and the supply controller, are in the following state: ? slow clock (slck) source is the internal 32 khz rc oscillator (32 khz crystal oscillator is disabled) ? main clock (mainck) source is set to the 4 mhz internal rc oscillator ? 3 - 20 mhz crystal oscillator and plls are disabled ? core brownout detector and core reset are enabled ? backup power-on-reset is enabled ? vddio supply monitor is disabled ? flash wait state (fws) bit in the eefc flash mode register is set to 0 ? core 0 cache controller (cmcc0) is enabled (only used if application link address for the core 0 is 0x11000000) ? sub-system 1 is in reset state and not clocked 5.3.3 device configuration after a reset after a reset or a wake-up from backup mode, the following system peripherals default to the same state as after a power cycle: ? main clock (mainck) source is set to the 4 mhz internal rc oscillator ? 3 - 20 mhz crystal oscillator and plls are disabled ? flash wait state (fws) bit in the eefc flash mode register is set to 0 ? core 0 cache controller (cmcc0) is enabled (only used if the application link address for the core 0 is 0x11000000) ? sub-system 1 is in the reset state and not clocked the states of the other peripherals are saved in the backup area managed by the supply controller as long as vddbu is maintained during device reset: ? slow clock (slck) source selection is written in supc_ cr.xtalsel. ? core brownout detector enable/disable is written in supc_mr.boddis. ? backup power-on-reset enable/disable is written in the supc_mr.bupporen. ? vddio supply monitor mode is written in the supc_smmr. 5.4 active mode active mode is the normal running mode with single or dual core executing code. the system clock can be the fast rc oscillator, the main crystal oscillator or the plls. the power management controller (pmc) can be used to adapt the frequency and to disable the peripheral clocks when not used.
21 sam4cp [datasheet] 43051e?atpl?08/14 5.5 low-power modes the various low-power modes (backup, wait and sleep modes) of the sam4cp are described below. note that the segmented lcd controller can be used in all low-power modes. note: the wait for event instruction (wfe) of the cortex-m4 core can be used to enter any of the low-power modes, however this may add complexity in the design of application state machines. this is due to the fact that the wfe instruction goes along with an event flag of the cortex core (cannot be managed by the software applica- tion). the event flag can be set by interrupts, a debug event or an event signal from another processor. since it is possible for an interrupt to occur just before the execution of wfe, wfe takes into account events that hap- pened in the past. as a result, wfe prevents the device from entering low-power mode if an interrupt event has occurred. atmel has made provision to avoid using the wfe instruction. the work arounds to ease application design are given in the following description of the low-power modes sequence. using the wfe instruction is given as well. 5.5.1 backup mode the purpose of backup mode is to achieve the lowest possible power consumption in a system that executes periodic wake-ups to perform tasks but which does not require fast start-up time. the supply controller, power-on reset, rtt, rtc, backup registers and the 32 khz oscillator (rc or crystal oscillator selected by software in the supply control ler) are running. the regulator and th e core supplies are off. the power-on- reset on vddbu can be deactivated by software. the sam4cp can be awakened from backup mode through the force wake-up (fwup) pin, wkup0, wkup1 to wkup15 pins, the vddio supply monitor (sm) if vddio is supplied, or through an rtt or rtc wake-up event. wake- up pins multiplexed with anti-tampering functions are possible sources of wake up as well in case if an anti-tampering event is detected. the tmp0 pad is supplied by the backup power supply (vddbu). other anti-tamper input pads are supplied by vddio. the lcd controller can be used in this mode. the purpose is to maintain the displayed message on the lcd display after entering the backup mode. the current consumption on vddin to maintain the lcd is 10 a typical. in case if the vddio power supply is kept on with vddbu when entering backup mode, it is up to the application to configure all pio lines in a stable and known state to avoid extra power consumption or possible current path with the input/output lines of the external on-board devices. 5.5.1.1 entering and exiting backup mode to enter backup mode, follow the steps in the sequence below: 1. depending on the application, set the pio lines in the correct mode and configuration (input pull-up or pull-down, output low or high levels). 2. disable the main crystal oscillator (enabled by sam-ba boot if device is booting from rom). 3. configure pa30/pa31 (xin/xout) into pio mode according to their use. 4. disable jtag lines via the sfr1 register in matrix 0 (by default, internal pull-up or pull-down is disabled on jtag lines). 5. enable rtt in 1 hz mode. 6. disable normal mode of rtt (rtt will run in 1 hz mode). 7. disable por backup if not needed (provides power-saving). 8. disable core brownout detector. 9. select one of the following methods to complete the sequence: a. to enter backup mode using the vroff bit: ? write a 1 to the vroff bit of supc_cr. b. to enter backup mode using the wfe instruction: ? write a 1 to the sleepdeep bit of the cortex-m4 processor. ? execute the wfe instruction of the processor.
sam4cp [datasheet] 43051e?atpl?08/14 22 after this step, the core voltage regulator is shut down and th e shdn pin goes low. all the digital internal logic (cores, peripherals and memories) is not powered. the lcd controller can be enabled if needed before entering backup mode. whether the vroff bit or the wfe instruction was used to enter backup mode, the system exits backup mode if one of the following enabled wake-up events occurs: ? wkup[0-15] pins ? force wake-up pin ? vddio supply monitor (if vddio is present, and vddio supply falling) ? anti-tamper event detection ? rtc alarm ? rtt alarm after exiting backup mode, the device is in the reset state. only the configuration of the backup area peripherals remains unchanged. note that the device does not automatically enter backup mode if vddin is disconnected, or if it falls below minimum voltage. the shutdown pin (shdn) remains high in this case. for current consumption in backup mode, refer to the section ?electrical characteristics?. 5.5.2 wait mode the purpose of wait mode is to achieve very low power consumption while maintaining the whole device in a powered state for a start-up time of less than 10 s. for current consumption in wait mode, refer to the electrical characteristics of this datasheet. in this mode, the bus and peripheral clocks of sub-system 0 and sub-system 1 (mck/cpbmck), the clocks of core 0 and core 1 (hclk/cphclk) are stopped when th e entering wait mode sequence is performed (see section 5.5.2.1 ). however, the power supply of core, peripherals and memories is maintained using the standby mode of the core voltage regulator. the sam4cp is able to handle external and internal events in order to perform a wake-up. this is done by configuring the external wkupx lines as fast startup wake-up pins (refer to section 5.7 ?fast start-up? ). rtc alarm, rtt alarm and anti-tamper events can wake the device up as well. the wait mode can be used together with the flash in read-idle mode, standby mode or deep power mode to further reduce the current consumption. flash in read-idle mode provides a faster start-up and the standby mode offers a lower power consumption. for further details, see the ?low-power wake-up time? section of the product electrical characteristics. 5.5.2.1 entering and exiting wait mode 1. stop sub-system 1. 2. select the 4/8/12 mhz fast rc oscillator as main clock (1) . 3. depending on the application, set the pio lines in the correct mode and configuration (input pull-up or pull-down, output low or high level). 4. disable the main crystal oscillator (enabled by sam-ba boot if device is booting from rom). 5. configure pa30/pa31 (xin/xout) into pio mode according to their use. 6. disable jtag lines via sfr1 register in matrix 0 (by default, internal pull-up or pull-down is disabled on jtag lines). 7. set the flpm field in the pmc fast startup mode register (pmc_fsmr) (2) . 8. set the flash wait state (fws) bit in the eefc flash mode register to 0. 9. select one of the following methods to complete the sequence: a. to enter wait mode using the waitmode bit: ? set the waitmode bit to 1 in the pmc main oscillator register (ckgr_mor). ? wait for master clock ready mckrdy = 1 in the pmc status register (pmc_sr).
23 sam4cp [datasheet] 43051e?atpl?08/14 b. to enter wait mode using the wfe instruction: ? select the 4/8/12 mhz fast rc oscillator as main clock. ? set the flpm field in the pmc fast startup mode register (pmc_fsmr). ? set flash wait state at 0. ? set the lpm bit in the pmc fast startup mode register (pmc_fsmr). ? write a 0 to the sleepdeep bit of the cortex-m4 processor. ? execute the wait-for-event (wfe) instruction of the processor. notes: 1. any frequency can be chosen. the 12 mhz frequency will provide a faster start-up compared to the 4 mhz, but with the increased current consumption (in the a range). see electrical characteristics of the product. 2. depending on the flash low-power mode (flpm) value, the flash enters three different modes: ? if flpm = 0, the flash enters stand-by mode (low consumption) ? if flpm = 1, the flash enters deep power-down mode (extra low consumption) ? if flpm = 2, the flash enters idle mode. memory is ready for read access whether the waitmode bit or the wfe instruction was used to enter wait mode, the system exits wait mode if one of the following enabled wake-up events occurs: ? wkup[0-15] pins in fast wake-up mode ? anti-tamper event detection ? rtc alarm ? rtt alarm after exiting wait mode, the pio controller has the same configuration state as before entering wait mode. the sam4cp is clocked back to the rc oscillator frequency which was used before entering wait mode. the core will start fetching from flash at this frequency. depending on configuration of the flash low-power mode (flpm) bits used to enter wait mode, the application has to reconfigure it back to read idle mode. 5.5.3 sleep mode the purpose of sleep mode is to optimize power consumption of the device versus response time. in this mode, only the core clocks of cm4p0 and/or cm4p1 are stopped. some of the peripheral clocks can be enabled depending on the application needs. the current consumption in this mode is application dependent. this mode is entered via wait for interrupt (wfi) or wait for event (wfe) instructions of the cortex-m4. the processor can be awakened from an interrupt if the wfi instruction of the cortex-m4 is used to enter sleep mode, or from an event if the wfe instruction is used. the wfi instruction can also be used to enter sleep mode with the sleeponexit bit set to 1 in the system control register (scb_scr) of the cortex-m. if the sleeponexit bit of the scb_scr is set to 1, when the processor completes the execution of an exception handler it returns to thread mode and enters immediately sleep mode. this mechanism can be used in applications that require the processor to run only when an exception occurs. setting the sleeponexit bit to 1 enables an interrupt-driven application in order to avoid returning to an empty main application.
sam4cp [datasheet] 43051e?atpl?08/14 24 5.5.4 low-power mode summary table the modes detailed above are the main low-power modes. table 5-2 below provides a configuration summary of the low- power modes. notes: 1. refer to the note in section 5.5 ?low-power modes? . 2. when considering wake-up time, the time required to start the pll is not taken into account. once started, the device works either from the 4, 8 or 12 mhz fast rc oscillator. the user has to add the pll start-up time if it is needed in the system. the wake-up time is defined as the time taken for wake-up until the first instruction is fetched. 3. refer to table 3-1, ?signal description list? . some anti-tamper pin pads are vddio powered. 4. see pio controller multiplexing tables in section 11.4 ?peripheral signal multiplexing on i/o lines? . 5. refer to the section electrical characteristics. 6. fast rc oscillator set to 4 mhz frequency. 7. lcd voltage regulator can be off if vddlcd is supplied externally thus saving current consumption of the lcd voltage regulator. 8. in this mode, the core is supplied and not clocked but some peripherals can be clocked. 9. depends on mck frequency. table 5-2. low-power mode configuration summary mode supc, 32 khz oscillator, rtc, rtt backup registers, por (backup region) core regulator / lcd regulator core 0/1 memory peripherals mode entry (1) potential wake-up sources core at wake-up pio state in low- power mode pio state at wake-up current consumption wake-up time (2) backup mode on off/off off / off (not powered) vroff bit = 1 or sleepdeep = 1 + wfe - fwup pin - wkup0-15 pins (3) - supply monitor - anti-tamper inputs (3) - rtc or rtt alarm reset previous state saved reset state (4) (5) < 1,5 ms backup mode with lcd on off/on off / off (not powered) vroff bit = 1 or sleepdeep = 1 + wfe - fwup pin - wkup0-15 pins (3) - supply monitor - anti-tamper inputs (3) - rtc or rtt alarm reset previous state saved unchanged (lcd pins)/ inputs with pull ups < 1,5 ms wait mode flash in standby mode (6) on on/ (7) core 0 and 1, memories and peripherals: powered, but not clocked waitmode = 1 + flpm = 0 or sleepdeep = 0 + lpm = 1 + flpm = 0 + wfe any event from: - fast start-up through wkup0-15 pins - anti-tamper inputs (3) - rtc or rtt alarm clocked back previous state saved unchanged < 10 s wait mode flash in deep power- down mode (6) on on/ (7) core 0 and 1, memories and peripherals: powered, but not clocked waitmode = 1 + flpm = 1 or sleepdeep = 0 + lpm = 1 + flpm = 1 + wfe any event from: - fast start-up through wkup0-15 pins - anti-tamper inputs (3) - rtc or rtt alarm clocked back previous state saved unchanged < 75 s sleep mode on on/ (7) core 0 and/or core 1: powered (not clocked) (8) sleepdeep = 0 + lpm = 0 + wfe or wfi entry mode = wfi any enabled interrupts; entry mode = wfe any enabled events: - fast start-up through wkup0-15 pins - anti-tamper inputs (3) - rtc or rtt alarm clocked back previous state saved unchanged (9) (9)
25 sam4cp [datasheet] 43051e?atpl?08/14 5.6 wake-up sources wake-up events allow the device to exit backup mode. when a wake-up event is detected, the supply controller performs a sequence which automatically reenables the device. 5.7 fast start-up the sam4cp allows the processor to restart in a few microseconds while the processor is in wait mode or in sleep mode. a fast start-up occurs upon detection of one of the wake-up inputs. the fast restart circuitry is fully asynchronous and provide s a fast start-up signal to the power management controller. as soon as the fast start-up signal is asserted, the pmc automatically restarts the embedded 4/8/12 mhz fast rc oscillator, switches the master clock on this 4 mhz clock and reenables the processor clock.
sam4cp [datasheet] 43051e?atpl?08/14 26 6. input/output lines the sam4cp has two types of input/output (i/o) lines: general purpose i/os (gpio) and system i/os. gpios have alternate functionality due to multiplexing capabilities of the pio controllers. the same pio line can be used whether in i/o mode or by the multiplexed peripheral. system i/os include pins such as test pins, oscillators, erase or analog inputs. 6.1 general purpose i/o lines gpio lines are managed by pio controllers. all i/os have se veral input or output modes such as pull-up or pull-down, input schmitt triggers, multi-drive (open-drain), glitch filters, debouncing or input change interrupt. programming of these modes is performed independently for each i/o line through th e pio controller user interface. for more details, refer to the ?parallel input/output (pio) controller? section of this datasheet. the input/output buffers of the pio lines are supplied t hrough vddio power supply rail when used as general purpose ios (gpios). when used as extra functions like lcd or analog modes, gpio lines have either vddlcd or vddin voltage range. each i/o line embeds an odt (on-die termination) shown in figure 6-1 below. odt consists of an internal series resistor termination scheme for impedance matching between the driver output (sam4cp) and the pcb trace impedance preventing signal reflection. the series resistor helps to reduce ios switching current (di/dt) thereby reducing emi. it also decreases overshoot and undershoot (ringing) due to inductance of interconnect between devices or between boards. finally, odt helps diminish signal integrity issues. figure 6-1. on-die termination 6.2 system i/o lines system i/o lines are pins used by oscillators, test mode, reset and jtag, to name but a few. described below in table 6- 1 are the sam4cp system i/o lines shared with pio lines. these pins are software configurable as general purpose i/o or system pins. at start-up, the default function of these pins is always used. notes: 1. if pc9 is used as pio input in user applications, a low level must be ensured at start-up to prevent flash erase before the user application sets pc9 into pio mode. 2. refer to the section ?3 to 20 mhz crystal oscillator?. pcb trace z0 ~ 50 ohms receiver sam4 driver with rodt zout ~ 10 ohms z0 ~ zout + rodt odt 36 ohms typ. table 6-1. system i/o configuration pin list system_io bit number default function after reset other function constraints for normal start configuration 0 tdi pb0 - in matrix user interface registers (refer to the system i/o configuration register in the ?bus matrix? section of this datasheet) 1 tdo/traceswo pb1 - 2 tms/swdio pb2 - 3 tck/swclk pb3 - 4 erase pc9 low level at start-up (1) - pa31 xin - (2) - pa30 xout -
27 sam4cp [datasheet] 43051e?atpl?08/14 6.2.1 serial wire jtag debug port (swj-dp) and serial wire debug port (sw-dp) pins the swj-dp pins are tck/swclk, tms/swdio, tdo/traceswo, tdi and commonly provided on a standard 20-pin jtag connector defined by arm. for more details about voltage reference and reset state, refer to table 11-6, ?multiplexing on pio controller b (piob)? . at start-up, swj-dp pins are configured in swj-dp mode to allow connection with debugging probe. refer to the ?debug and test? section of this datasheet. swj-dp pins can be used as standard i/os to provide users with more general input/output pins when the debug port is not needed in the end application. mode selection betwee n swj-dp mode (system io mode) and general io mode is performed through the ahb matrix special function registers (matrix_sfr). configuration of the pad for pull-up, triggers, debouncing and glitch filters is possible regardless of the mode. the jtagsel pin is used to select the jtag boundary scan when asserted at a high level. it integrates a permanent pull-down resistor of about 15 k ? to gnd, so that it can be left unconnected for normal operations. by default, the jtag debug port is active. if the debugger host wants to switch to the serial wire debug port, it must provide a dedicated jtag sequence on tms/swdio and tck/swclk which di sables the jtag-dp and enables the sw-dp. when the serial wire debug port is active, tdo/traceswo can be used for trace. the asynchronous trace output (traceswo) is multiplexed with tdo. so the asynchronous trace can only be used with sw-dp, not jtag-dp. for more information about sw-dp and jtag-dp switching, refer to the ?debug and test? section of this datasheet. the sw-dp/swj-dp pins are used for debug access to both cores. 6.3 test pin the tst pin is used for jtag boundary scan manufacturing test or fast flash programming mode of the sam4cp series. for details on entering fast programming mode, see the ?fast flash programming interface (ffpi)? section of this datasheet. for more information on the manufacturing and test modes, refer to the ?debug and test? section of this datasheet. 6.4 nrst pin the nrst pin is bidirectional. it is handled by the on-chip reset controller and can be driven low to provide a reset signal to the external components or asserted low externally to reset the microcontroller. it resets the core and the peripherals except the backup region (rtc, rtt and supply controller). there is no constraint on the length of the reset pulse and the reset controller can guarantee a minimum pulse length. the nrst pin integrates a permanent pull-up resistor to vddio of about 100 k ? . by default, the nrst pin is configured as an input. 6.5 tmpx pins: anti-tamper pins anti-tamper pins detect intrusion, for example, into a smart meter case. upon detection through a tamper switch, automatic, asynchronous and immediate clear of registers in the backup area, and time stamping in the rtc will be performed. anti-tamper pins can be used in all modes. date and number of tampering events are stored automatically. anti-tampering events can be programmed so that half of the general purpose backup registers (gpbr) are erased automatically. tmp1 to tmp3 signals are shared with a pio pin meaning that vddio must be supplied, whereas tmp0 is in the vddbu domain. 6.6 rtcout0 pin the rtcout0 pin shared in the pio (supplied by vddio) can be used to generate waveforms from the rtc in order to take advantage of the rtc inherent prescalers while the rtc is the only powered circuitry (low-power mode of operation, backup mode) or in any active mode. entering backup or low-power operating modes does not affect the waveform generation outputs (vddio needs still to be supplied). anti-tampering pin detection can be synchronised with this signal. note: to use the rtcout0 signal during application development via jtag-ice interface, the programmer must use serial wire debug (swd) mode. in this case, the tdo pin is not used as a jtag signal by the ice interface.
sam4cp [datasheet] 43051e?atpl?08/14 28 6.7 shutdown (shdn) pin the shdn pin reflects the mcu backup mode of operation: when the mcu is in backup mode, shdn = 0, otherwise shdn = 1 (vddbu). this pin is designed to control the enable pin of the main external voltage regulator. when the mcu enters backup mode, the shdn pin disables the external volt age regulator and, upon wake-up event, it re-enables the voltage regulator. the shdn pin is used to control an external main voltage regulator and/or power switch when entering backup mode. the shdn pin is asserted low when the vroff bit in the supply controller control register (supc_cr) is set to 1. 6.8 force wake-up (fwup) pin the fwup pin can be used as a wake-up source in all low-power modes as it is supplied by vddbu. 6.9 erase pin the erase pin is used to reinitialize the flash content (and some of its nvm bits) to an erased state (all bits read as logic level 1). the erase pin integrates a pull-down resistor of about 100 k ? into gnd, so that it can be left unconnected for normal operations. this pin is debounced by slck to improve the glitch tolerance. when the erase pin is tied high during less than 100 ms, it is not taken into account. the pin must be tied high during more than 220 ms to perform a flash erase operation. the erase pin is a system i/o pin and can be used as a standard i/o. at start-up, the erase pin is not configured as a pio pin. if the erase pin is used as a standard i/o, the start-up level of this pin must be low to prevent unwanted erasing. refer to section 11.3 ?apb/ahb bridge? on page 44 . if the erase pin is used as a standard i/o output, asserting the pin to low does not erase the flash. to avoid unexpected erase at power-up, a minimum erase pin assertion time is required. this time is defined in the ac flash characteristics in the electrical characteristics. the erase operation is not performed when the system is in wait mode with the flash in deep-power-down mode. to make sure that the erase operation is performed after power-up, the system must not reconfigure the erase pin as gpio or enter wait mode with flash in deep-power-down mode before the erase pin assertion time has elapsed. with the following sequence, in any case, the erase operation is performed: 1. assert the erase pin (high). 2. assert the nrst pin (low). 3. power cycle the device. 4. maintain the erase pin high for at least the minimum assertion time.
29 sam4cp [datasheet] 43051e?atpl?08/14 7. product mapping and peripheral access figure 7-1. memory mapping of code and sram area notes: 1. boot memory for core 0. 2. boot memory for core 1 at 0x00000000. address memory space code 0x00000000 internal sram 0x20000000 peripherals 0x40000000 reserved 0x60000000 external devices 0xa0000000 cortex-m private peripheral bus 0xe0000000 reserved 0xe0100000 0xffffffff code boot memory (1) (code - non cached) 0x00000000 internal flash (code - non cached) 0x01000000 internal rom 0x02000000 reserved 0x03000000 reserved 0x04000000 reserved 0x05000000 reserved 0x06000000 undefined (abort) 0x07000000 undefined (abort) 0x10000000 internal flash (code - cached) 0x11000000 undefined (abort) 0x12000000 reserved 0x13000000 reserved 0x14000000 reserved 0x15000000 reserved 0x16000000 undefined (abort) 0x17000000 0x1fffffff internal sram sram0 0x20000000 sram1 (2) 0x20080000 sram2 0x20100000 cpkcc rom 0x20180000 reserved 0x20190000 cpkcc sram 0x20191000 reserved 0x20192000 undefined (abort) 0x20200000 0x3fffffff external devices reserved 0xa0000000 reserved 0xa1000000 reserved 0xa2000000 reserved 0xa3000000 undefined (abort) 0xa4000000 0xdfffffff offset id (+ : wired-or) peripheral block
sam4cp [datasheet] 43051e?atpl?08/14 30 figure 7-2. memory mapping of the peripherals area address memory space code 0x00000000 internal sram 0x20000000 peripherals 0x40000000 reserved 0x60000000 external devices 0xa0000000 cortex-m private peripheral bus 0xe0000000 reserved 0xe0100000 0xffffffff peripherals aes 36 0x40000000 reserved 0x40004000 pplc 21 0x40008000 reserved 0x4000c000 tc0 tc0 0x40010000 23 tc0 tc1 +0x40 24 tc0 tc2 +0x80 25 tc1 tc3 0x40014000 26 tc1 tc4 +0x40 27 tc1 tc5 +0x80 28 twi0 19 0x40018000 twi1 20 0x4001c000 reserved 0x40020000 usart0 14 0x40024000 usart1 15 0x40028000 usart2 16 0x4002c000 usart3 17 0x40030000 usart4 18 0x40034000 adc 29 0x40038000 slcdc 32 0x4003c000 cpkcc 35 0x40040000 icm 34 0x40044000 trng 33 0x40048000 ipc0 31 0x4004c000 reserved 0x40050000 cmcc0 0x4007c000 reserved 0x40080000 system controller 0x400e0000 reserved 0x400e4000 spi1 40 0x48000000 uart1 38 0x48004000 pwm 41 0x48008000 pioc 37 0x4800c000 matrix1 0x48010000 ipc1 39 0x48014000 cmcc1 0x48018000 reserved 0x4801c000 reserved 0x48020000 0x5fffffff system controller reserved 0x400e0000 matrix0 0x400e0200 pmc 5 0x400e0400 uart0 8 0x400e0600 chipid 0x400e0740 reserved 0x400e0800 efc 6 0x400e0a00 reserved 0x400e0c00 pioa 11 0x400e0e00 piob 12 0x400e1000 reserved 0x400e1200 sysc rstc 0x400e1400 1 sysc supc +0x10 sysc rtt +0x30 3 sysc wdt +0x50 4 sysc rtc +0x60 2 sysc gpbr +0x90 sysc rswdt +0x100 reserved 0x400e1600 0x400e4000 0x48004000
31 sam4cp [datasheet] 43051e?atpl?08/14 in figure 7-1 , ?code? means ?program code over i-code bus? and ?program data over d-code bus?. sram1 shown in the mapping above can be seen at the address 0x20080000 (through s-bus) and the address 0x00000000 (through i/d bus) for core 1. instruction fetch from core 1 to the sram address range is possible but leads to reduced performance due to the fact that instructions and read/write data go through the system bus (s-bus). maximum performance for core 1 is obtained by mapping the instruction code to the address 0x00000000 (sram1 through i/d-code) and read/write data from the address 0x20100000 (sram2 through s-bus). for core 0 (application core), maximum performance is achieved when the instruction code is mapped to the flash address and read/write data is mapped into sram0. each cores can access the following memories and peripherals: ? core 0 (application core): ? all internal memories ? all internal peripherals ? core 1 (coprocessor core): ? all internal memories ? all internal peripherals note that peripheral dma 0 on matrix 0 cannot access sram1 or sram2, peripheral dma 1 on matrix 1 cannot access sram0, sram2 or sram0 can be the data ram for inter-core communication. if the core 1 is not to be used (clock stopped and reset active), all the peripherals, sram1 and sram2 of the sub- system 1 can be used by the application core (core 0) as long as the peripheral bus clock and reset are configured. detailed memory mapping and memory access versus matrix masters/slaves is given in the ?bus matrix (matrix)? section of this datasheet.
sam4cp [datasheet] 43051e?atpl?08/14 32 8. memories the memory map shown in figure 7-1, ?memory mapping of code and sram area? is global to both cortex-m4 processors except the ?boot memory? block. for mor e information on boot memory please refer to section 8.1.5 ?boot strategy? on page 36 . each processor uses its own arm private bus memory map for the nvic and other system functions. 8.1 embedded memories 8.1.1 internal sram the sam4cp embeds a total of 152 kbytes high-speed sram with zero wait state access time. sram0 on matrix0 is 128 kbytes. it is dedicated to the application processo r (cm4p0) or other peripherals on matrix0 but can be identified and used by masters on matrix1. please refer to ?bus matrix (matrix)? section of this datasheet for more details. sram1 on matrix1 is 16 kbytes. it is mainly dedicated to be the code region of the cm4p1 processor but can be identified and used by on matrix0. please refer to ?bus matrix (matrix)? section of this datasheet for more details. sram2 on matrix1 is 8 kbytes. it is mainly dedicated to be the data region of the cm4p1 processor or other peripherals on matrix1 but can be identified and used by masters on matri x0. please refer to ?bus matrix (matrix)? section of this datasheet for more details. if the cm4p1 processor is in the reset state and not used, the application core can use it. the sram is located in the bit band region. the bit band alias region is from 0x2200 0000 to 0x23ff_ffff. 8.1.2 system rom the sam4cp embeds an internal rom for the master processor (cm4p0), which contains the sam boot assistant (sam-ba), in application programming routines (iap), and fast flash programming interface (ffpi). the rom is always mapped at the address 0x02000000. 8.1.3 cpkcc rom the rom contains a cryptographic library using the cpkcc cryptographic accelerator peripheral (cpkcc) to provide support for rivest shamir adleman (rsa), elliptic curve cryptography (ecc), digital signature algorithm (dsa) and elliptic curve digital signature algorithm (ecdsa). 8.1.4 embedded flash 8.1.4.1 flash overview the embedded flash is the boot memory for the cortex-m4 core 0 (cm4p0). the flash memory can be accessed through the cache memory controller (cmcc0) of the cm4p0 and can also be identified by the cortex-m4f core 1 (cm4p1) through its cache memory controller (cmcc1). the memory plane is organized in sectors. each sector has a size of 64 kbytes. the first sector of 64 kbytes is divided into 3 smaller sectors. the three smaller sectors are organized into 2 sectors of 8 kbytes and 1 sector of 48 kbytes. refer to figure 8-1 below. the flash memory has a built-in error code correction provides 2-bit error detection and 1-bit correction per 128 bits.
33 sam4cp [datasheet] 43051e?atpl?08/14 figure 8-1. memory plane organization each sector is organized in pages of 512 bytes. for sector 0: ? the smaller sector 0 has 16 pages of 512 bytes, 8 kbytes in total. ? the smaller sector 1 has 16 pages of 512 bytes, 8 kbytes in total. ? the larger sector has 96 pages of 512 bytes, 48 kbytes in total. from sector 1 to n: the rest of the array is composed of 64-kbyte sector where each sector comprises 128 pages of 512 bytes. refer to figure 8-2, ?flash sector organization? below. figure 8-2. flash sector organization in sam4cp16b the flash size is 1024 kbytes. flash organization small sector 0 8 kbytes small sector 1 8 kbytes larger sector 48 kbytes sector 1 64 kbytes 64 kbytes sector n sector 0 sector size sector name sector 0 sector n smaller sector 0 smaller sector 1 larger sector flash sector organization a sector size is 64 kbytes 16 pages of 512 bytes 16 pages of 512 bytes 16 pages of 512 bytes 96 pages of 512 bytes 128 pages of 512 bytes
sam4cp [datasheet] 43051e?atpl?08/14 34 figure 8-3 illustrates the organization of the flash depending on flash size. figure 8-3. flash size the following erase commands can be used depending on the sector size: ? 8 kbyte small sector ? erase and write page (ewp). ? erase and write page and lock (ewpl). ? erase sector (es) with farg set to a page number in the sector to erase. ? erase pages (epa) with farg [1:0] = 0 to erase four pages or farg [1:0] = 1 to erase eight pages. farg [1:0] = 2 and farg [1:0] = 3 must not be used. ? 48 kbyte and 64 kbyte sectors ? one block of 8 pages inside any sector, with the command erase pages (epa) with farg[1:0] = 1. ? one block of 16 pages inside any sector, with the command erase pages (epa) and farg[1:0] = 2. ? one block of 32 pages inside any sector, with the command erase pages (epa) and farg[1:0] = 3. ? one sector with the command erase sector (es) and farg set to a page number in the sector to erase. ? entire memory plane ? the entire flash, with the command erase all (ea). 8.1.4.2 enhanced embedded flash controller the enhanced embedded flash controller manages accesses performed by masters of the system. it enables reading the flash and writing the write buffer. it also contains a user interface, mapped on the apb. the enhanced embedded flash controller ensures the interface of the flash block. it manages the programming, erasing, locking and unlocking sequences of the flash using the full set of commands. one of the commands returns the embedded flash descriptor definition that informs the system about the flash organization, thus making the software generic. 8.1.4.3 flash speed the user needs to set the number of wait states depending on the frequency used on the sam4cp. for more details, refer to the ?ac characteristics? section of the product electrical characteristics. 2 * 8 kbytes 1 * 48 kbytes 15 * 64 kbytes flash 1 mbytes
35 sam4cp [datasheet] 43051e?atpl?08/14 8.1.4.4 lock regions several lock bits are used to protect write and erase operations on lock regions. a lock region is composed of several consecutive pages, and each lock region has its associated lock bit. the lock bits are software programmable through the eefc user interface. the command ?set lock bit? enables the protection. the command ?clear lock bit? unlocks the lock region. asserting the erase pin clears the lock bits, thus unlocking the entire flash. 8.1.4.5 security bit feature the sam4cp features a security bit based on a specific general purpose nvm bit (gpnvm bit 0). when the security is enabled, any access to the flash, sram, core registers and internal peripherals, either through the sw-dp/jtag-dp interface or through the fast flash programming interface, is forbidden. this ensures the confidentiality of the code programmed in the flash. this security bit can only be enabled through the command ?set general purpose nvm bit 0? of the eefc user interface. disabling the security bit can only be achieved by asserting the erase pin at 1, and after a full flash erase is performed. when the security bit is deactivated, all accesses to the flash, sram, core registers, internal peripherals are permitted. 8.1.4.6 unique identifier each device integrates its own 128-bit unique identifier. these bits are factory configured and cannot be changed by the user. the erase pin has no effect on the unique identifier. 8.1.4.7 user signature the memory has one additional reprogrammable page that can be us ed as page signature by the user. it is accessible through specific modes, for erase, write and read operations. erase pin assertion will not erase the user signature page. 8.1.4.8 fast flash programming interface the fast flash programming interface allows programming the device through either a serial jtag interface or through a multiplexed fully-handshaked parallel port. it allows gang programming with market-standard industrial programmers. the ffpi supports read, page program, page erase, full erase, lock, unlock and protect commands. 8.1.4.9 sam-ba boot the sam-ba boot is a default boot program for the master processor (cm4p0) which provides an easy way to program in-situ the on-chip flash memory. the sam-ba boot assistant supports serial communication via the uart0. the sam-ba boot provides an interface with sam-ba graphic user interface (gui). the sam-ba boot is in rom and is mapped in flash at address 0x0 when gpnvm bit 1 is set to 0. 8.1.4.10 gpnvm bits the sam4cp features two gpnvm bits. these bits can be cleared or set respectively through the commands ?clear gpnvm bit? and ?set gpnvm bit? of the eefc user interface. table 8-1. lock bit number product number of lock bits lock region size sam4cp16b 128 8 kbytes table 8-2. general-purpose nonvolatile memory bits gpnvmbit[#] function 0 security bit 1 boot mode selection
sam4cp [datasheet] 43051e?atpl?08/14 36 8.1.5 boot strategy figure 8-4 below shows a load view of the memory at boot time. figure 8-4. simplified load view at boot time 8.1.5.1 application core (core 0) boot process the application processor (cm4p0) always boots at the address 0x0. to ensure maximum boot possibilities, the memory layout can be changed via gpnvm. a general purpose nvm (gpnvm) bit is used to boot either on the rom (default) or from the flash. the gpnvm bit can be cleared or set through the commands ?clear general-purpose nvm bit? and ?set general-purpose nvm bit? of the eefc user interface respectively. setting gpnvm bit 1 selects the boot from the flash whereas clearing this bit selects the boot from the rom. asserting erase clears the gpnvm bit 1 and thus selects the boot from the rom by default. 8.1.5.2 coprocessor core (core 1) boot process after reset, the sub-system 1 is hold in reset and with no clock. it is up to the master application (core 0 application) running on the core 0 to enable the sub-system 1. then the application code can be downloaded into the cm4p1 boot memory (sram1), and cm4p0 can afterwards deassert the cm4p1 reset line. the secondary processor (cm4p1) always identifies sram1 as ?boot memory?. 8.1.5.3 sub-system 1 startup sequence after the core 0 is booted from flash, the core 0 application must perform the following steps: 1. enable core 1 system clock (bus and peripherals). 2. enable core 1 clock. 3. release core 1 system reset (bus and peripherals). 4. enable sram1 and sram2 clock. 5. copy core 1 application from flash into sram1. 6. release core 1 reset. after step 6, the core 1 boots from sram1 memory. sram0 sram1 core 0 application core (cortex-m4) icode / dcode bus s-bus icode / dcode bus s-bus sram2 flash core 0 application core1 application (binary img.) clock & reset control core 1 coprocessor core (cortex-m4f) sub-system 0 sub-system 1 note: matrices, ahb and apb bridges are not represented. mpu nvic fpu nvic
37 sam4cp [datasheet] 43051e?atpl?08/14 pseudo-code 1- // enable coprocessor bus master clock in pmc system clock enable register (cpbmck bit) 2- // enables coprocessor clocks ? pmc system clock enable register (cpck bit) // set coprocessor clock prescaler and source ? in pmc mckr: coprocessor programmable clock prescaler (cppres bit fields) // choose coprocessor main clock source ? in pmc mckr: coprocessor master clock selection (cpcss bit fields) 3- // release coprocessor peripheral reset ? in reset controller coprocessor mode register (cperen bit) 4- // enable core 1 sram1 and sram2 memories ? in pmc pcer: peripheral id 42 (sram) 5- // at this point core 1 application code must be loaded from flash into sram1. 6- // release coprocessor reset ? in reset controller coprocessor mode register (cprocen bit) 8.1.5.4 sub-system 1 start-up time table 8-3 provides the start-up time of sub-system 1 in terms of the number of clock cycles for different cpu speeds. the figures in this table take into account the time to copy 16 kbytes of code from flash into sram1 using the ?memcopy? function from the standard c library and to release core 1 reset signal. the start-up time of the device from power-up is not taken into account . table 8-3. sub-system 1 start-up time core clock (mhz) flash wait state core clock cycles time 21 0 44122 2.1 ms 42 1 45158 1.07 ms 63 2 46203 735 s 85 3 47242 55 s 106 4 48284 455 s 120 5 49329 411 s
sam4cp [datasheet] 43051e?atpl?08/14 38 8.1.5.5 typical execution view figure 8-5 below provides the code execution view for both cortex-m4 cores. ahb to apb, ahb to ahb and matrices are not represented in this view. figure 8-5. execution view sram0 core 0, rw data, stack, heap core 0 application core (cortex-m4) core 1 coprocessor core (cortex-m4f) flash core 0 code, ro data core 1 code, ro data core 1 application binary cache ctrl. (cmcc0) cache ctrl. (cmcc1) sram1 sram2 note: 1. sram0 can also be used as message buffer exchange. note: matrices, ahb and apb bridges are not represented. mpu nvic fpu nvic core 1, rw data, stack, heap core 0 <--> core 1 msg. buffer (1) core 1 code, ro data sub-system 0 sub-system 1 icode / dcode bus icode / dcode bus s-bus s-bus s-bus icode / dcode bus
39 sam4cp [datasheet] 43051e?atpl?08/14 9. real-time event management the events generated by peripherals are designed to be directly routed to peripherals managing/using these events without processor intervention. peripherals receiving events contain logic to select the required event. 9.1 embedded characteristics ? timers generate event triggers which are directly routed to event managers, such as adc, to start measurement/conversion without processor intervention. ? uart, usart, spi, twi, and pio generate event triggers directly connected to peripheral dma controller (pdc) for data transfer without processor intervention. ? pmc security event (clock failure detection) can be programmed to switch the mck on reliable main rc internal clock. 9.2 real-time event mapping list table 9-1. real-time event mapping list event generator event manager function anti-tamper inputs (tmpx) general purpose backup register (gpbr) security / immediate gpbr clear (asynchronous) on anti-tamper detection through pins power management controller (pmc) pmc safety / automatic switch to reliable main rc oscillator in case of main crystal clock failure io (adtrg) adc trigger for measurement. selection in adc module tc output 0 adc trigger for measurement. selection in adc module tc output 1 adc trigger for measurement. selection in adc module tc output 2 adc trigger for measurement. selection in adc module tc output 3 adc trigger for measurement. selection in adc module tc output 4 adc trigger for measurement. selection in adc module tc output 5 adc trigger for measurement. selection in adc module
sam4cp [datasheet] 43051e?atpl?08/14 40 10. system controller the system controller comprises a set of peripherals. it handles key elements of the system, such as power, resets, clocks, time, interrupts, watchdog, reinforced safety watchdog, etc. see the system controller block diagram in figure 10-1 . figure 10-1. system controller block diagram core voltage regulator matrix x 2 sram0/1/2 watchdog timer cortex-m4 x2 flash peripherals peripheral bridge x2 zero-power power-on reset supply monitor (backup) rtc power management controller embedded 32 khz rc oscillator xtal 32 khz oscillator embedded 12/8/4 mhz rc oscillator supply controller brownout detector (core) reset controller backup power supply core power supply pllb vr_on vr_mode on out rtc_alarm slck rtc_nreset proc_nreset periph_nreset ice_nreset master clock mck0 / mck1 slck nrst mainck fstt0 - fstt15 xin32 xout32 osc32k_xtal_en slow clock slck osc32k_rc_en vddio vddcore vddout advref adx wkup0 - wkup15 bod_core_on lcore_brown_out rtt rtt_alarm slck rtt_nreset xin xout vddio vddin piox vddlcd pllbck main clock mainck slck 3 - 20 mhz xtal oscillator vddio xtalsel gene ral pu rpose ba ckup registers vddcore_nreset vddcore_nreset pioa/b/c input/output buffers adc analog circuitry fstt0 - fstt15 are possible fast startup sources, generated by wkup0 - wkup15 pins, but are not physical pins. automatic power switch vddbu fwkup tmp0 on plla slck pllack lcd voltage regulator lcd controller shdn
41 sam4cp [datasheet] 43051e?atpl?08/14 10.1 system controller and peripheral mapping refer to ?memory mapping of code and sram area? . all the peripherals are in the bit band region and are mapped in the bit band alias region. 10.2 power supply monitoring the sam4cp embeds supply monitor, power-on-reset and brownout detectors for power supplies monitoring allowing to warn and/or reset the chip. 10.2.1 power-on-reset on vddcore the power-on-reset monitors vddcore. it is always activated and monitors voltage at start-up but also during power- down. if vddcore goes below the threshold voltage, the entire chip (except vddbu domain) is reset. for more information, refer to the ?electrical characteristics? section of the product datasheet. 10.2.2 brownout detector on vddcore the brownout detector monitors vddcore. it is active by default. it can be deactivated by software through the supply controller (supc_mr). if vddcore goes below the threshold voltage, the reset of the core is asserted. 10.2.3 power-on-reset on vddio the power-on-reset monitors vddio. it is always activated and monitors voltage at start-up but also during power- down. if vddio goes below the threshold voltage, the ios are reset but the core continues to run. voltage detection is fixed. 10.2.4 supply monitor on vddio the supply monitor on vddio is fully programmable with 16 steps for the threshold (between 1.6v to 3.4v). it provides the user the flexibility to set a voltage level detection higher then the power-on-reset on vddio. either a reset or an interrupt can be generated upon de tection. it can be activate d by software and it is cont rolled by the supply controller (supc). a sample mode is possible. it divides the supply monitor power consumption by a factor of up to 2048. the supply monitor is used as ?system alert? in case vddio supply is falling. it can be used while the device is in backup mode to wake up the device if vddio is falling. 10.2.5 power-on-reset and brownout detector on vddbu the power-on-reset monitors vddbu. it is active by default and monitors voltage at start-up but also during power- down. it can be deactivated by software through the supply controller (supc_mr). if vddbu goes below the threshold voltage, the entire chip is reset. 10.3 reset controller the reset controller uses the power-on-reset supply monitor, and brownout detector cells. the reset controller returns to the software either the source of the last reset, or of a general reset, a wake-up reset, a software reset, a user reset, a watchdog or reinforced watchdog reset. the reset controller controls the internal resets of the system (or independent reset of cm4p1 processor) and the nrst pin input/output. it shapes a reset signal for the external devices, simplifying to a minimum connection of a push-button on the nrst pin to implement a manual reset. the configuration of the reset controller is saved as its is supplied by vddbu. 10.4 supply controller (supc) the supply controller controls the power supplies of each section of the processor. the supply controller starts up the device by sequentially enabling the internal power switches and the voltage regulator, then it generates the proper reset signals to the core power supply. it also sets the system in different low-power modes, wakes it up from a wide range of events.
sam4cp [datasheet] 43051e?atpl?08/14 42 11. peripherals 11.1 peripheral identifiers table 11-1 defines the peripheral identifiers of the sam4cp. a peripheral identifier is required for the control of the peripheral interrupt with the nested vectored interrupt controller, and for the control of the peripheral clock with the power management controller. the two arm cortex-m4 processors share the same interrupt mapping, and thus, they share all the interrupts of the peripherals. note: note some peripherals are on the bus matrix 0/ahb to abp bridge 0 and other peripherals are on the bus matrix 1/ahb to abp bridge 1. if core 0 needs to access a peripheral on the bus matrix 1/ahb to abp bridge 1, the core 0 application must enable the core 1 system clock (bus and peripherals) and release core 1 system reset (bus and peripherals). peripherals on sub-system 0 or sub-system 1 are mentioned in the instance description table that follows. table 11-1. peripheral identifiers instance id instance name nvic interrupt pmc clock control instance description 0 supc x - supply controller 1 rstc x - reset controller 2 rtc x - real-time clock 3 rtt x - real-time timer 4 wdt x - watchdog timer/reinforced watchdog timer 5 pmc x - power management controller 6 efc x - enhanced embedded flash controller 0 7 --- reserved 8 uart0 x x uart 0 (sub-system 0 clock) 9 - - - reserved 10 - - - reserved 11 pioa x x parallel i/o controller a (sub-system 0 clock) 12 piob x x parallel i/o controller b (sub-system 0 clock) 13 --- reserved 14 usart0 x x usart 0 (sub-system 0 clock) 15 usart1 x x usart 1 (sub-system 0 clock) 16 usart2 x x usart 2 (sub-system 0 clock) 17 usart3 x x usart 3 (sub-system 0 clock) 18 usart4 x x usart 4 (sub-system 0 clock) 19 twi0 x x two wire interface 0 (sub-system 0 clock) 20 twi1 x x two wire interface 1 (sub-system 0 clock) 21 pplc x x power line communication (sub-system 0 clock) 22 --- reserved 23 tc0 x x timer/counter 0 (sub-system 0 clock) 24 tc1 x x timer/counter 1 (sub-system 0 clock) 25 tc2 x x timer/counter 2 (sub-system 0 clock)
43 sam4cp [datasheet] 43051e?atpl?08/14 11.2 peripheral dma controller two peripheral dma controllers (pdc) are available: ? pdc0: dedicated to peripherals on apb0 ? pdc1: dedicated to peripherals on apb1 features of the pdc include: ? data transfer handling between peripherals and memories ? low bus arbitration overhead ? one master clock cycle needed for a transfer from memory to peripheral ? two master clock cycles needed for a transfer from peripheral to memory ? next pointer management for reducing interrupt latency requirement note that peripheral dma 0 on matrix 0 cannot access sram1 or sram2. peripheral dma 1 on matrix 1 cannot access sram0. 26 tc3 x x timer/counter 3 (sub-system 0 clock) 27 tc4 x x timer/counter 4 (sub-system 0 clock) 28 tc5 x x timer/counter 5 (sub-system 0 clock) 29 adc x x analog to digital converter (sub-system 0 clock) 30 arm x - fpu signals (only on cm4p1 core): fpixc, fpofc, fpufc, fpioc, fpdzc, fpidc, fpixc 31 ipc0 x x interprocessor communication 0 (sub-system 0 clock) 32 slcdc x x segment lcd controller (sub-system 0 clock) 33 trng x x true random generator (sub-system 0 clock) 34 icm x x integrity check module (sub-system 0 clock) 35 cpkcc x x classical public key cryptography controller (sub- system 0 clock) 36 aes x x advanced enhanced standard (sub-system 0 clock) 37 pioc x x parallel i/o controller c (sub-system 1 clock) 38 uart1 x x uart 1 (sub-system 1 clock) 39 ipc1 x x interprocessor communication 1 (sub-system 1 clock) 40 spi1 x x serial peripheral interface 1 (sub-system 1 clock) 41 pwm x x pulse width modulation (sub-system 1 clock) 42 sram - x sram1 (i/d code bus of cm4p1), sram2 (system bus of cm4p1) (sub-system 1 clock) 43 - - - reserved table 11-1. peripheral identifiers (continued) instance id instance name nvic interrupt pmc clock control instance description
sam4cp [datasheet] 43051e?atpl?08/14 44 the peripheral dma controller handles tran sfer requests from the channel accordin g to the following priorities (low to high priorities): 11.3 apb/ahb bridge the sam4cp embeds two peripheral bridges: one on each matrix (matrix 0 for cm4p0 and matrix 1 for cm4p1). the peripherals of the bridge corresponding to cm4p0 (apb0) are clocked by mck, and the peripherals of the bridge corresponding to cm4p1 (apb1) are clocked by cpbmck. 11.4 peripheral signal multiplexing on i/o lines the sam4cp can multiplex the i/o lines of the peripheral set. the sam4cp pio controllers control up to 32 lines. each line can be assigned to one of two peripheral functions: a or b. the multiplexing tables in the paragraphs that follow define how the i/o lines of the peripherals a and b are multiplexed on the pio controllers. the column ?comments? has been inserted in this table for the user?s own comments; it may be used to track how pins are defined in an application. note that some peripheral functions which are output only, might be duplicated within the tables. table 11-2. peripheral dma controller (pdc0) instance name channel t/r aes transmit twi0 transmit uart0 transmit usart1 transmit usart0 transmit usart2 transmit usart3 transmit usart4 transmit pplc transmit aes receive twi0 receive uart0 receive usart4 receive usart3 receive usart2 receive usart1 receive usart0 receive adc receive pplc receive table 11-3. peripheral dma controller (pdc1) instance name channel t/r uart1 transmit spi1 transmit uart1 receive spi1 receive
45 sam4cp [datasheet] 43051e?atpl?08/14 11.4.1 pad features in table 11-5 to table 11-7 , the column ?feature? indicates whether the corresponding i/o line has programmable pull- up, pull-down and/or schmitt trigger. table 11-4 provides the key to the abbreviations used. 11.4.2 reset state in table 11-5 to table 11-7 , the column ?reset state? indicates the reset state of the line. ? pio or signal name: indicates whether the pio line resets in i/o mode or in peripheral mode. if ?pio? is mentioned, the pio line is in general purpose i/o (gpio). if a signal name is mentioned in the ?reset state? column, the pio line is assigned to this function. ? i or o: indicates whether the signal is input or output state. ? pu or pd: indicates whether pull-up, pull-down or nothing is enabled. ? st: indicates if schmitt trigger is enabled. table 11-4. i/o line features abbreviations abbreviation definition pup (p) programmable pull-up pup (np) non-programmable pull-up pdn (p) programmable pull-down pdn (np) non-programmable pull-down st (p) programmable schmitt trigger st (np) non-programmable schmitt trigger ldrv (p) programmable low drive ldrv (np) non-programmable low drive hdrv (p) programmable high drive hdrv (np) non-programmable high drive maxdrv (p) programmable maximum drive maxdrv (np) non-programmable maximum drive
sam4cp [datasheet] 43051e?atpl?08/14 46 11.4.3 pio controller a multiplexing table 11-5. multiplexing on pio controller a (pioa) i/o line peripheral a peripheral b peripheral c extra function system function feature reset state comments pa0 rts3 pck2 com0 wkup5 - pup(p) / pdn(p) - st(p) - maxdrv(np) pio, i, pu pa1 cts3 com1 - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pa2 sck3 com2 pa3 rxd3 com3 wkup6 pa4 txd3 com4/ad1 pa9 rxd2 seg3 wkup2 - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pa10 txd2 seg4 pa11 rxd1 seg5 wkup9 pa12 txd1 seg6/ad0 pa13 sck2 tioa0 seg7 pa14 rts2 tiob0 seg8 wkup3 pa15 cts2 tioa4 seg9 pa16 sck1 tiob4 seg10 pa17 rts1 tclk4 seg11 wkup7 pa18 cts1 tioa5 seg12 pa19 rts0 tclk5 seg13 wkup4 pa20 cts0 tiob5 seg14 pa21 seg15 pa22 seg16 pa23 seg17 pa24 twd0 seg18 wkup1 pa25 twck0 seg19 pa26 cts4 seg20 pa27 seg21 pa28 seg22 pa29 pck1 seg23 - pup(p) / pdn(p) - st(p) - maxdrv(np) pa30 pck1 xout - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) xout pa31 pck0 xin - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) xin
47 sam4cp [datasheet] 43051e?atpl?08/14 11.4.4 pio controller b multiplexing table 11-6. multiplexing on pio controller b (piob) i/o line peripheral a peripheral b peripheral c extra function system function feature reset state comments pb0 twd1 tdi - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) jtag, i pb1 twck1 rtcout0 tdo/ traceswo - pup(p)/pdn(p) - ldrv(np) jtag, o pb2 tms/swdio - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) jtag, i pb3 tck/swclk pb4 urxd0 tclk0 wkup8 pio, i, pu pb5 utxd0 pb6 seg24 pb7 tioa1 seg25 pb8 tiob1 seg26 pb9 tclk1 seg27 pb10 tioa2 seg28 pb11 tiob2 seg29 pb12 tclk2 seg30 pb13 pck0 seg31/ad3 - pup(p) / pdn(p) - st(p) - maxdrv(np) pb14 seg32 - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pb15 seg33 pb16 rxd0 seg34 wkup10/ tmp1 pio, i, pd pb17 txd0 seg35 pb18 sck0 pck2 seg36 pb19 rxd4 seg37 pb20 txd4 seg38 pb21 sck4 seg39 wkup11 pb22 rts4 seg40 pio, i, pu pb23 adtrg seg41/ad4 pb24 tioa3 seg42 pb25 tiob3 seg43 pb26 tclk3 seg44 wkup13 pb27 seg45 wkup14/ tmp2 pb28 seg46 wkup15/ tmp3 pb29 seg47 pb31 seg49/ad5
sam4cp [datasheet] 43051e?atpl?08/14 48 11.4.5 pio controller c multiplexing table 11-7. multiplexing on pio controller c (pioc) i/o line peripheral a peripheral b peripheral c extra function system function feature reset state comments pc0 utxd1 pwm0 - pup(p) - maxdrv(np) pio, i, pu pc1 urxd1 pwm1 wkup12 - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pc2 spi1_npcs0 pwm2 pc3 spi1_miso pwm3 pc4 spi1_mosi pc5 spi1_spck - pup(p) - maxdrv(np) pc6 pwm0 spi1_npcs1 - pup(p) / pdn(p) - st(p) - ldrv(p) / hdrv(p) pc7 pwm1 spi1_npcs2 pc8 pwm2 spi1_npcs3 pc9 pwm3 erase erase, pd
49 sam4cp [datasheet] 43051e?atpl?08/14 12. arm cortex-m4 processor 12.1 description the cortex-m4 processor is a high performance 32-bit processor designed for the microcontroller market. it offers significant benefits to developers, including outstanding p rocessing performance combined with fast interrupt handling, enhanced system debug with extensive breakpoint and trace capabilities, efficient processor core, system and memo- ries, ultra-low power consumption with integrated sleep modes, and platform security robustness , with integrated memory protection unit (mpu). the cortex-m4 processor is built on a high-performance processor core, with a 3-stage pipeline harvard architecture, making it ideal for demanding embedded applications. the processor delivers exceptional power efficiency through an efficient instruction set and extensively optimized design, providing high-end processing hardware including ieee754- compliant single-precision floating-point computation, a range of single-cycle and simd multiplication and multiply-with- accumulate capabilities, saturating arithmetic and dedicated hardware division. to facilitate the design of cost-sensitive devices, the cortex-m4 processor implements tightly-coupled system compo- nents that reduce processor area while significantly improving interrupt handling and system debug capabilities. the cortex-m4 processor implements a version of the thumb in struction set based on thumb- 2 technology, ensuring high code density and reduced program memory requirements. the cortex-m4 instruction set provides the exceptional perfor- mance expected of a modern 32-bit architecture, with the high code density of 8-bit and 16-bit microcontrollers. the cortex-m4 processor closely integrates a configurable nvic, to deliver industry-leading interrupt performance. the nvic includes a non-maskable interrupt (nmi), and provides up to 256 interrupt priority levels. the tight integration of the processor core and nvic provides fast execution of interrupt service routines (isrs), dramatically reducing the interrupt latency. this is achieved through the hardware stacking of registers, and the ability to suspend load-multiple and store- multiple operations. interrupt handlers do not require wrapping in assembler code, removing any code overhead from the isrs. a tail-chain optimization also significantly reduces the overhead when switching from one isr to another. to optimize low-power designs, the nvic integrates with the sleep modes, that include a deep sleep function that enables the entire device to be rapidly powered down while still retaining program state. 12.1.1 system level interface the cortex-m4 processor provides multiple interfaces using amba ? technology to provide high speed, low latency memory accesses. it supports unaligned data accesses and implements atomic bit manipulation that enables faster peripheral controls, system spinlocks and thread-safe boolean data handling. the cortex-m4 processor has a memory protection unit (mpu) that provides fine grain memory control, enabling appli- cations to utilize multiple privilege levels, separating and pr otecting code, data and stack on a task-by-task basis. such requirements are becoming critical in many embedded applications such as automotive. 12.1.2 integrated configurable debug the cortex-m4 processor implements a complete hardware debug solution. this provides high system visibility of the processor and memory through either a tradi tional jtag port or a 2-pin serial wire debug (swd) port that is ideal for microcontrollers and other small package devices. for system trace the processor integrates an instrumentation trace macrocell (itm) alongside data watchpoints and a profiling unit. to enable simple and cost-effective profiling of the system events these generate, a serial wire viewer (swv) can export a stream of software-generated messages, data trace, and profiling information through a single pin. the flash patch and breakpoint unit (fpb) provides up to 8 hardware breakpoint comparators that debuggers can use. the comparators in the fpb also provide remap functions of up to 8 words in the program code in the code memory region. this enables applications stored on a non-erasable, rom-based microcontroller to be patched if a small pro- grammable memory, for example flash, is available in the device. during initialization, the application in rom detects, from the programmable memory, whether a patch is required. if a patch is required, the application programs the fpb to remap a number of addresses. when those addresses are accessed, the accesses are redirected to a remap table specified in the fpb configuration, which means the program in the non-modifiable rom can be patched.
50 sam4cp [datasheet] 43051e?atpl?08/14 12.2 embedded characteristics ? tight integration of system peripherals reduces area and development costs ? thumb instruction set combines high code density with 32-bit performance ? ieee754-compliant single-precision fpu ? code-patch ability for rom system updates ? power control optimization of system components ? integrated sleep modes for low power consumption ? fast code execution permits slower processor clock or increases sleep mode time ? hardware division and fast digital-signal-processing oriented multiply accumulate ? saturating arithmetic for signal processing ? deterministic, high-performance interrupt handling for time-critical applications ? memory protection unit (mpu) for safety-critical applications ? extensive debug and trace capabilities: ? serial wire debug and serial wire trace reduce the number of pins required for debugging, tracing, and code profiling. 12.3 block diagram figure 12-1. typical cortex-m4f implementation nvic debug access port memory protection unit serial wire viewer bus matrix code interface sram and peripheral interface data watchpoints flash patch fpu processor core cortex-m4f processor
51 sam4cp [datasheet] 43051e?atpl?08/14 12.4 cortex-m4 models 12.4.1 programmers model this section describes the cortex-m4 programmers model. in addition to the individual core register descriptions, it con- tains information about the processor modes and privilege levels for software execution and stacks. 12.4.1.1 processor modes and privilege levels for software execution the processor modes are: ? thread mode used to execute application software. the processor enters the thread mode when it comes out of reset. ? handler mode used to handle exceptions. the processor returns to the thread mode when it has finished exception processing. the privilege levels for software execution are: ? unprivileged the software: ? has limited access to the msr and mrs instructions, and cannot use the cps instruction ? cannot access the system timer, nvic, or system control block ? might have a restricted access to memory or peripherals unprivileged software executes at the unprivileged level. ? privileged the software can use all the instructions and has access to all resources. privileged software executes at the privileged level. in thread mode, the control register controls whether the software execution is privileged or unprivileged, see ?control register? . in handler mode, software execution is always privileged. only privileged software can write to the control register to change the privilege level for software execution in thread mode. unprivileged software can use the svc instruction to make a supervisor call to transfer control to privileged software. 12.4.1.2 stacks the processor uses a full descending stack. this means the stack pointer holds the address of the last stacked item in memory when the processor pushes a new item onto the stack, it decrements the stack pointer and then writes the item to the new memory location. the processor implements two stacks, the main stack and the process stack , with a pointer for each held in independent registers, see ?stack pointer? . in thread mode, the control register controls whether the processor uses the main stack or the process stack, see ?con- trol register? . in handler mode, the processor always uses the main stack. the options for processor operations are: note: 1. see ?control register? . table 12-1. summary of processor mode, execution privilege level, and stack use options processor mode used to execute privilege level for software execution stack used thread applications privileged or unprivileged (1) main stack or process stack (1) handler exception handlers always privileged main stack
52 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.3 core registers figure 12-2. processor core registers notes: 1. describes access type during program execution in thread mode and handler mode. debug access can differ. 2. an entry of either means privileged and unprivileged software can access the register. sp (r13) lr (r14) pc (r15) r5 r6 r7 r0 r1 r3 r 4 r2 r10 r11 r12 r8 r9 low registers high registers msp ? psp ? psr primask faultmask basepri control general-purpose registers stack pointer link register program counter program status register exception mask registers control register special registers ? banked version of sp table 12-2. core processor registers register name access (1) required privilege (2) reset general-purpose registers r0-r12 read/write either unknown stack pointer msp read/write privileged see description stack pointer psp read/write either unknown link register lr read/write either 0xffffffff program counter pc read/write either see description program status register psr read/write privileged 0x01000000 application program status register apsr read/write either 0x00000000 interrupt program status register ipsr read-only privileged 0x00000000 execution program status register epsr read-only privileged 0x01000000 priority mask register primask read/write privileged 0x00000000 fault mask register faultmask read/write privileged 0x00000000 base priority mask register basepri read/write privileged 0x00000000 control register control read/write privileged 0x00000000
53 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.4 general-purpose registers r0-r12 are 32-bit general-purpose registers for data operations. 12.4.1.5 stack pointer the stack pointer (sp) is register r13. in thread mode, bit[1] of the control register indicates the stack pointer to use: ? 0 = main stack pointer (msp). this is the reset value ? 1 = process stack pointer (psp) on reset, the processor loads the msp with the value from address 0x00000000. 12.4.1.6 link register the link register (lr) is register r14. it stores the return information for subroutines, function calls, and exceptions. on reset, the processor loads the lr value 0xffffffff. 12.4.1.7 program counter the program counter (pc) is register r15. it cont ains the current program address. on reset, the processor loads the pc with the value of the reset vector, which is at address 0x00000004. bit[0] of the value is loaded into the epsr t-bit at reset and must be 1.
54 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.8 program status register name: psr access: read/write reset: 0x00000000 the program status register (psr) combines: ? application program status register (apsr). ? interrupt program status register (ipsr). ? execution program status register (epsr). these registers are mutually exclusive bitfields in the 32-bit psr. the psr accesses these registers individually or as a combination of any two or all three registers, using the register name as an argument to the msr or mrs instructions. for example: ? read of all the registers using psr with the mrs instruction. ? write to the apsr n, z, c, v and q bits using apsr_nzcvq with the msr instruction. the psr combinations and attributes are: notes: 1. the processor ignores writes to the ipsr bits. 2. reads of the epsr bits return zero, and the processor ignores writes to these bits. see the instruction descriptions ?mrs? and ?msr? for more information about how to access the program status registers. 31 30 29 28 27 26 25 24 n z c v q ici/it t 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ici/it ? isr_number 76543210 isr_number name access combination psr read/write (1)(2) apsr, epsr, and ipsr iepsr read-only epsr and ipsr iapsr read/write (1) apsr and ipsr eapsr read/write (2) apsr and epsr
55 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.9 application program status register name: apsr access: read/write reset: 0x00000000 the apsr contains the current state of the condition flags from previous instruction executions. ? n: negative flag 0: operation result was positive, zero, greater than, or equal. 1: operation result was negative or less than. ? z: zero flag 0: operation result was not zero. 1: operation result was zero. ? c: carry or borrow flag carry or borrow flag: 0: add operation did not result in a carry bit or subtract operation resulted in a borrow bit. 1: add operation resulted in a carry bit or subtract operation did not result in a borrow bit. ? v: overflow flag 0: operation did not result in an overflow. 1: operation resulted in an overflow. ? q: dsp overflow and saturation flag sticky saturation flag: 0: indicates that saturation has not occurred since reset or since the bit was last cleared to zero. 1: indicates when an ssat or usat instruction results in saturation. this bit is cleared to zero by software using an mrs instruction. ? ge[19:16]: greater than or equal flags see ?sel? for more information. 31 30 29 28 27 26 25 24 nzcvq ? 23 22 21 20 19 18 17 16 ? ge[3:0] 15 14 13 12 11 10 9 8 ? 76543210 ?
56 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.10 interrupt program status register name: ipsr access: read/write reset: 0x00000000 the ipsr contains the exception type number of the current interrupt service routine (isr). ? isr_number: number of the current exception 0 = thread mode 1 = reserved 2 = nmi 3 = hard fault 4 = memory management fault 5 = bus fault 6 = usage fault 7-10 = reserved 11 = svcall 12 = reserved for debug 13 = reserved 14 = pendsv 15 = systick 16 = irq0 56 = irq40 see ?exception types? for more information. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? isr_number 76543210 isr_number
57 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.11 execution program status register name: epsr access: read/write reset: 0x00000000 the epsr contains the thumb state bit, and the execution state bits for either the if-then (it) instruction, or the interruptible- continuable instruction (ici) field for an interrupted load multiple or store multiple instruction. attempts to read the epsr directly through application software using the msr instruction always return zero. attempts to write the epsr using the msr instruction in the application software are ignored. fault handlers can examine the epsr value in the stacked psr to indicate the operation that is at fault. see ?exception entry and return? . ? ici: interruptible-continuable instruction when an interrupt occurs during the execution of an ldm, s tm, push, pop, vldm, vstm, vpush, or vpop instruction, the processor: ? stops the load multiple or store multiple instruction operation temporarily. ? stores the next register operand in the multiple operation to epsr bits[15:12]. after servicing the interrupt, the processor: ? returns to the register pointed to by bits[15:12]. ? resumes the execution of the multiple load or store instruction. when the epsr holds the ici execution state, bits[26:25,11:10] are zero. ? it: if-then instruction indicates the execution state bits of the it instruction. the if-then block contains up to four instructions following an it instruction. each instruction in the block is conditional. t he con- ditions for the instructions are either all the same, or some can be the inverse of others. see ?it? for more information. ? t: thumb state the cortex-m4 processor only supports the execution of instructions in thumb state. the following can clear the t bit to 0: ? instructions blx, bx and pop{pc}. ? restoration from the stacked xpsr value on an exception return. ? bit[0] of the vector value on an exception entry or reset. attempting to execute instructions when the t bit is 0 results in a fault or lockup. see ?lockup? for more information. 12.4.1.12 exception mask registers the exception mask registers disable the handling of exceptions by the processor. disable exceptions where they might impact on timing critical tasks. to access the exception mask registers use the msr and mrs instructions, or the cps instruction to change the value of primask or faultmask. see ?mrs? , ?msr? , and ?cps? for more information. 31 30 29 28 27 26 25 24 ? ici/it t 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ici/it ? 76543210 ?
58 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.13 priority mask register name: primask access: read/write reset: 0x00000000 the primask register prevents the activation of all exceptions with a configurable priority. ? primask 0: no effect. 1: prevents the activation of all exceptions with a configurable priority. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? primask
59 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.14 fault mask register name: faultmask access: read/write reset: 0x00000000 the faultmask register prevents the activation of all exceptions except for non-maskable interrupt (nmi). ? faultmask 0: no effect. 1: prevents the activation of all exceptions except for nmi. the processor clears the faultmask bit to 0 on exit from any exception handler except the nmi handler. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? faultmask
60 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.15 base priority mask register name: basepri access: read/write reset: 0x00000000 the basepri register defines the minimum priority for exception processing. when basepri is set to a nonzero value, it prevents the activation of all exceptions with same or lower priority level as the basepri value. ? basepri priority mask bits: 0x0000 : no effect. nonzero: defines the base priority for exception processing. the processor does not process any exception with a priority value greater than or equal to basepri. this field is similar to the priority fields in the interrupt priority registers. the processor implements only bits[7:4] of th is field, bits[3:0] read as zero and ignore writes. see ?interrupt priority registers? for more information. remember that higher priority field values correspond to lower exception priorities. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 basepri
61 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.16 control register name: control access: read/write reset: 0x00000000 the control register controls the stack used and the privilege level for software execution when the processor is in thread mode and indicates whether the fpu state is active. ? fpca: floating-point context active indicates whether the floating-point context is currently active: 0: no floating-point context active. 1: floating-point context active. the cortex-m4 uses this bit to determine whether to preserve the floating-point state when processing an exception. ? spsel: active stack pointer defines the current stack: 0: msp is the current stack pointer. 1: psp is the current stack pointer. in handler mode, this bit reads as zero and ignores writes. the cortex-m4 updates this bit automatically on exception return. ? npriv: thread mode privilege level defines the thread mode privilege level: 0: privileged. 1: unprivileged. handler mode always uses the msp, so the processor ignores explicit writes to the active stack pointer bit of the control regis ter when in handler mode. the exception entry and return mechanisms update the control register based on the exc_return value. in an os environment, arm recommends that threads running in thread mode use the process stack, and the kernel and exception handlers use the main stack. by default, the thread mode uses the msp. to switch the stack pointer used in thread mode to the psp, either: ? use the msr instruction to set the active stack pointer bit to 1, see ?msr? . ? perform an exception return to thread mode with the appropriate exc_return value, see table 12-10 . note: when changing the stack pointer, the software must use an isb instruction immediately after the msr instruction. this ensures that instructions after the isb execute using the new stack pointer. see ?isb? . 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? fpca spsel npriv
62 sam4cp [datasheet] 43051e?atpl?08/14 12.4.1.17 exceptions and interrupts the cortex-m4 processor supports interrupts and system exceptions. the processor and the nested vectored interrupt controller (nvic) prioritize and handle all exceptions. an exception changes the normal flow of software control. the pro- cessor uses the handler mode to handle all exceptions except for reset. see ?exception entry? and ?exception return? for more information. the nvic registers control interrupt handling. see ?nested vectored interrupt controller (nvic)? for more information. 12.4.1.18 data types the processor supports the following data types: ? 32-bit words. ? 16-bit halfwords. ? 8-bit bytes. ? the processor manages all data memory accesses as little-endian. instruction memory and private peripheral bus (ppb) accesses are always little-endian. see ?memory regions, types and attributes? for more information. 12.4.1.19 cortex microcontroller software interface standard (cmsis) for a cortex-m4 microcontroller system, the cortex microcontroller software interface standard (cmsis) defines: ? a common way to: ? access peripheral registers. ? define exception vectors. ? the names of: ? the registers of the core peripherals. ? the core exception vectors. ? a device-independent interface for rtos kernels, including a debug channel. the cmsis includes address definitions and data structures for the core peripherals in the cortex-m4 processor. the cmsis simplifies the software development by enabling the reuse of template code and the combination of cmsis- compliant software components from various middleware vendors. software vendors can expand the cmsis to include their peripheral definitions and access functions for those peripherals. this document includes the register names defined by the cmsis, and gives short descriptions of the cmsis functions that address the processor core and the core peripherals. note: this document uses the register short names defined by the cmsis. in a few cases, these differ from the archi- tectural short names that might be used in other documents. the following sections give more information about the cmsis: ? section 12.5.3 ?power management programming hints? ? section 12.6.2 ?cmsis functions? ? section 12.8.2.1 ?nvic programming hints?
63 sam4cp [datasheet] 43051e?atpl?08/14 12.4.2 memory model this section describes the processor memory map, the behavior of memory accesses, and the bit-banding features. the processor has a fixed memory map that provides up to 4gb of addressable memory. figure 12-3. memory map the regions for sram and peripherals include bit-band regions. bit-banding provides atomic operations to bit data, see ?bit-banding? . the processor reserves regions of the private peripheral bus (ppb) address range for core peripheral registers. this memory mapping is generic to arm cortex-m4 products. to get the specific memory mapping of this product, refer to the memories section of the datasheet. vendor-specific memory external device external ram peripheral sram code 0xffffffff private peripheral bus 0xe0100000 0xe00fffff 0x9fffffff 0xa0000000 0x5fffffff 0x60000000 0x3fffffff 0x40000000 0x1fffffff 0x20000000 0x00000000 0x40000000 32 mb bit band alias 0x400fffff 0x42000000 0x43ffffff 1 mb bit band region 32 mb bit band alias 0x20000000 0x200fffff 0x22000000 0x23ffffff 1.0gb 1.0gb 0.5gb 0.5gb 0.5gb 1.0mb 511mb 1 mb bit band region 0xe0000000 0xdfffffff
64 sam4cp [datasheet] 43051e?atpl?08/14 12.4.2.1 memory regions, types and attributes the memory map and the programming of the mpu split the memory map into regions. each region has a defined memory type, and some regions have additional memory attributes. the memory type and attributes determine the behavior of accesses to the region. memory types ? normal the processor can re-order transactions for efficiency, or perform speculative reads. ? device the processor preserves transaction order relative to other transactions to device or strongly-ordered memory. ? strongly-ordered the processor preserves transaction order relative to all other transactions. the different ordering requirements for device and strongly-ordered memory mean that the memory system can buffer a write to device memory, but must not buffer a write to strongly-ordered memory. additional memory attributes ? shareable for a shareable memory region, the memory system provides data synchronization between bus masters in a system with multiple bus masters, for example, a processor with a dma controller. strongly-ordered memory is always shareable. if multiple bus masters can access a non-shareable memory region, the software must ensure data coherency between the bus masters. ? execute never (xn) means the processor prevents instruction accesses. a fault exception is generated only on execution of an instruction executed from an xn region. 12.4.2.2 memory system ordering of memory accesses for most memory accesses caused by explicit memory access instructions, the memory system does not guarantee that the order in which the accesses complete matches the program order of the instructions, providing this does not affect the behavior of the instruction sequence. normally, if correct program execution depends on two memory accesses completing in program order, the software must insert a memory barrier instruction between the memory access instructions, see ?software ordering of memory accesses? . however, the memory system does guarantee some ordering of accesses to device and strongly-ordered memory. for two memory access instructions a1 and a2, if a1 occurs before a2 in program order, the ordering of the memory accesses is described below. where: ? means that the memory system does not guarantee the ordering of the accesses. < means that accesses are observed in program order, that is, a1 is always observed before a2. table 12-3. ordering of the memory accesses caused by two instructions a2 normal access device access strongly-ordered access a1 non-shareable shareable normal access ? ? ? ? device access, non-shareable ? < ? < device access, shareable ? ? < < strongly-ordered access ? < < <
65 sam4cp [datasheet] 43051e?atpl?08/14 12.4.2.3 behavior of memory accesses the following table describes the behavior of accesses to each region in the memory map. note: 1. see ?memory regions, types and attributes? for more information. the code, sram, and external ram regions can hold programs. however, arm recommends that programs always use the code region. this is because the processor has separate buses that enable instruction fetches and data accesses to occur simultaneously. the mpu can override the default memory access behavior described in this section. for more information, see ?memory protection unit (mpu)? . additional memory access constraints for shared memory when a system includes shared memory, some memory regions have additional access constraints, and some regions are subdivided, as table 12-5 shows: notes: 1. see ?memory regions, types and attributes? for more information. table 12-4. memory access behavior address range memory region memory type xn description 0x00000000 - 0x1fffffff code normal (1) - executable region for program code. data can also be put here. 0x20000000 - 0x3fffffff sram normal (1) - executable region for data. code can also be put here. this region includes bit band and bit band alias areas, see table 12-6 . 0x40000000 - 0x5fffffff peripheral device (1) xn this region includes bit band and bit band alias areas, see table 12-6 . 0x60000000 - 0x9fffffff external ram normal (1) - executable region for data. 0xa0000000 - 0xdfffffff external device device (1) xn external device memory. 0xe0000000 - 0xe00fffff private peripheral bus strongly- ordered (1) xn this region includes the nvic, system timer, and system control block. 0xe0100000 - 0xffffffff reserved device (1) xn reserved. table 12-5. memory region shareability policies address range memory region memory type shareability 0x00000000 - 0x1fffffff code normal (1) - 0x20000000 - 0x3fffffff sram normal (1) - 0x40000000 - 0x5fffffff peripheral device (1) - 0x60000000 - 0x7fffffff external ram normal (1) - 0x80000000 - 0x9fffffff 0xa0000000 - 0xbfffffff external device device (1) shareable (1) 0xc0000000 - 0xdfffffff non-shareable (1) 0xe0000000 - 0xe00fffff private peripheral bus strongly- ordered (1) shareable (1) 0xe0100000 - 0xffffffff vendor-specific device device (1) -
66 sam4cp [datasheet] 43051e?atpl?08/14 instruction prefetch and branch prediction the cortex-m4 processor: ? prefetches instructions ahead of execution. ? speculatively prefetches from branch target addresses. 12.4.2.4 software ordering of memory accesses the order of instructions in the program flow does not always guarantee the order of the corresponding memory transactions. this is because: ? the processor can reorder some memory accesses to improve efficiency, providing this does not affect the behavior of the instruction sequence. ? the processor has multiple bus interfaces. ? memory or devices in the memory map have different wait states. ? some memory accesses are buffered or speculative. ?memory system ordering of memory accesses? describes the cases where the memory system guarantees the order of memory accesses. otherwise, if the order of memory accesses is critical, the software must include memory barrier instructions to force that ordering. the processor provides the following memory barrier instructions: dmb the data memory barrier (dmb) instruction ensures that outstanding memory transactions complete before subsequent memory transactions. see ?dmb? . dsb the data synchronization barrier (dsb) instruction ensures that outstanding memory transactions complete before subsequent instructions execute. see ?dsb? . isb the instruction synchronization barrier (isb) ensures that the effect of all completed memory transactions is recognizable by subsequent instructions. see ?isb? . mpu programming use a dsb followed by an isb instruction or exception return to ensure that the new mpu configuration is used by subsequent instructions. 12.4.2.5 bit-banding a bit-band region maps each word in a bit-band alias region to a single bit in the bit-band region . the bit-band regions occupy the lowest 1 mb of the sram and peripheral memory regions. the memory map has two 32 mb alias regions that map to two 1 mb bit-band regions: ? accesses to the 32 mb sram alias region map to the 1 mb sram bit-band region, as shown in table 12-6 . ? accesses to the 32 mb peripheral alias region map to the 1 mb peripheral bit-band region, as shown in table 12-7 . table 12-6. sram memory bit-banding regions address range memory region instruction and data accesses 0x20000000 - 0x200fffff sram bit-band region direct accesses to this memory range behave as sram memory accesses, but this region is also bit-addressable through bit-band alias. 0x22000000 - 0x23ffffff sram bit-band alias data accesses to this region are remapped to bit-band region. a write operation is performed as read-modify- write. instruction accesses are not remapped.
67 sam4cp [datasheet] 43051e?atpl?08/14 notes: 1. a word access to the sram or peripheral bit-band alias regions map to a single bit in the sram or peripheral bit-band region. 2. bit-band accesses can use byte, halfword, or word transfers. the bit-band transfer size matches the transfer size of the instruction making the bit-band access. the following formula shows how the alias region maps onto the bit-band region: bit_word_offset = (byte_offset x 32) + (bit_number x 4) bit_word_addr = bit_band_base + bit_word_offset where: ? bit_word_offset is the position of the target bit in the bit-band memory region. ? bit_word_addr is the address of the word in the alias memory region that maps to the targeted bit. ? bit_band_base is the starting address of the alias region. ? byte_offset is the number of the byte in the bit-band region that contains the targeted bit. ? bit_number is the bit position, 0-7, of the targeted bit. figure 12-4 shows examples of bit-band mapping between the sram bit-band alias region and the sram bit-band region: ? the alias word at 0x23ffffe0 maps to bit [0] of the bit-band byte at 0x200fffff: 0x23ffffe0 = 0x22000000 + (0xfffff*32) + (0*4). ? the alias word at 0x23fffffc maps to bit [7] of the bit-band byte at 0x200fffff: 0x23fffffc = 0x22000000 + (0xfffff*32) + (7*4). ? the alias word at 0x22000000 maps to bit [0] of the bit-band byte at 0x20000000: 0x22000000 = 0x22000000 + (0*32) + (0*4). ? the alias word at 0x2200001c maps to bit [7] of the bit-band byte at 0x20000000: 0x2200001c = 0x22000000 + (0*32) + (7*4). table 12-7. peripheral memory bit-banding regions address range memory region instruction and data accesses 0x40000000 - 0x400fffff peripheral bit-band alias direct accesses to this memory range behave as peripheral memory accesses, but this region is also bit- addressable through bit-band alias. 0x42000000 - 0x43ffffff peripheral bit-band region data accesses to this region are remapped to bit-band region. a write operation is performed as read-modify- write. instruction accesses are not permitted.
68 sam4cp [datasheet] 43051e?atpl?08/14 figure 12-4. bit-band mapping directly accessing an alias region writing to a word in the alias region updates a single bit in the bit-band region. bit[0] of the value written to a word in the alias region determines the value written to the targeted bit in the bit-band region. writing a value with bit[0] set to 1 writes a 1 to the bit-band bit, and writing a value with bit[0] set to 0 writes a 0 to the bit-band bit. bits[31:1] of the alias word have no effect on the bit-band bit. writing 0x01 has the same effect as writing 0xff . writing 0x00 has the same effect as writing 0x0e . reading a word in the alias region: ? 0x00000000 indicates that the targeted bit in the bit-band region is set to 0. ? 0x00000001 indicates that the targeted bit in the bit-band region is set to 1. directly accessing a bit-band region ?behavior of memory accesses? describes the behavior of direct byte, halfword, or word accesses to the bit-band regions. 12.4.2.6 memory endianness the processor views memory as a linear collection of bytes numbered in ascending order from zero. for example, bytes 0-3 hold the first stored word, and bytes 4-7 hold the second stored word. ?little-endian format? describes how words of data are stored in memory. little-endian format in little-endian format, the processor stores the least significant byte of a word at the lowest-numbered byte, and the most significant byte at the highest-numbered byte. for example: figure 12-5. little-endian format 0x23ffffe4 0x22000004 0x23ffffe0 0x23ffffe8 0x23ffffec 0x23fffff0 0x23fffff4 0x23fffff8 0x23fffffc 0x22000000 0x22000014 0x22000018 0x2200001c 0x22000008 0x22000010 0x2200000c 32 mb alias region 0 7 0 0 7 0x20000000 0x20000001 0x20000002 0x20000003 6 5 4 3 2 1 0 7 6 5 4 3 2 1 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0x200ffffc 0x200ffffd 0x200ffffe 0x200fffff 1 mb sram bit-band region memory register address a a+1 lsbyte msbyte a+2 a+3 0 7 b0 b1 b3 b2 31 24 23 16 15 8 7 0 b0 b1 b2 b3
69 sam4cp [datasheet] 43051e?atpl?08/14 12.4.2.7 synchronization primitives the cortex-m4 instruction set includes pairs of synchronization primitives . these provide a non-blocking mechanism that a thread or process can use to obtain exclusive access to a memory location. the software can use them to perform a guaranteed read-modify-write memory update sequence, or for a semaphore mechanism. a pair of synchronization primitives comprises: a load-exclusive instruction , used to read the value of a memory location, requesting exclusive access to that location. a store-exclusive instruction , used to attempt to write to the same memory location, returning a status bit to a register. if this bit is: ? 0: it indicates that the thread or process gained exclusive access to the memory, and the write succeeds. ? 1: it indicates that the thread or process did not gain exclusive access to the memory, and no write is performed. the pairs of load-exclusive and store-exclusive instructions are: ? the word instructions ldrex and strex. ? the halfword instructions ldrexh and strexh. ? the byte instructions ldrexb and strexb. the software must use a load-exclusive instruction with the corresponding store-exclusive instruction. to perform an exclusive read-modify-write of a memory location, the software must: 1. use a load-exclusive instruction to read the value of the location. 2. update the value, as required. 3. use a store-exclusive instruction to attempt to write the new value back to the memory location. 4. test the returned status bit. if this bit is: 0: the read-modify-write completed successfully. 1: no write was performed. this indicates that the value returned at step 1 might be out of date. the software must retry the read-modify-write sequence. the software can use the synchronization primitives to implement a semaphore as follows: 1. use a load-exclusive instruction to read from the semaphore address to check whether the semaphore is free. 2. if the semaphore is free, use a store-exclusive instruction to write the claim value to the semaphore address. 3. if the returned status bit from step 2 indicates that the store-exclusive instruction succeeded then the software has claimed the semaphore. however, if the store-exclusive instruction failed, another process might have claimed the semaphore after the software performed the first step. the cortex-m4 includes an exclusive access monitor, that ta gs the fact that the processor has executed a load-exclu- sive instruction. if the processor is part of a multiprocessor system, the system also globally tags the memory locations addressed by exclusive accesses by each processor. the processor removes its exclusive access tag if: ? it executes a clrex instruction. ? it executes a store-exclusive instruction, regardless of whether the write succeeds. ? an exception occurs. this means that the processor can resolve semaphore conflicts between different threads. in a multiprocessor implementation: ? executing a clrex instruction removes only the local exclusive access tag for the processor. ? executing a store-exclusive instruction, or an exception, removes the local exclusive access tags, and all global exclusive access tags for the processor. for more information about the synchronization primitive instructions, see ?ldrex and strex? and ?clrex? .
70 sam4cp [datasheet] 43051e?atpl?08/14 12.4.2.8 programming hints for the synchronization primitives iso/iec c cannot directly generate the exclusive access instructions. cmsis provides intrinsic functions for generation of these instructions: the actual exclusive access instruction generated depends on the data type of the pointer passed to the intrinsic function. for example, the following c code generates the required ldrexb operation: __ldrex((volatile char *) 0xff); 12.4.3 exception model this section describes the exception model. 12.4.3.1 exception states each exception is in one of the following states: inactive the exception is not active and not pending. pending the exception is waiting to be serviced by the processor. an interrupt request from a peripheral or from software can change the state of the corresponding interrupt to pending. active an exception is being serviced by the processor but has not completed. an exception handler can interrupt the exec ution of another exception handler. in this case, both exceptions are in the active state. active and pending the exception is being serviced by the processor and there is a pending exception from the same source. 12.4.3.2 exception types the exception types are: reset reset is invoked on power up or a warm reset. the except ion model treats reset as a special form of exception. when reset is asserted, the operation of the processor stops, potentially at any point in an instruction. when reset is deasserted, execution restarts from the address provided by the reset entry in the vector table. execution restarts as privileged execution in thread mode. non maskable interrupt (nmi) a non maskable interrupt (nmi) can be signalled by a peripheral or triggered by software. this is the highest priority exception other than reset. it is permanently enabled and has a fixed priority of -2. table 12-8. cmsis functions for exclusive access instructions instruction cmsis function ldrex uint32_t __ldrexw (uint32_t *addr) ldrexh uint16_t __ldrexh (uint16_t *addr) ldrexb uint8_t __ldrexb (uint8_t *addr) strex uint32_t __strexw (uint32_t value, uint32_t *addr) strexh uint32_t __strexh (uint16_t value, uint16_t *addr) strexb uint32_t __strexb (uint8_t value, uint8_t *addr) clrex void __clrex (void)
71 sam4cp [datasheet] 43051e?atpl?08/14 nmis cannot be: ? masked or prevented from activation by any other exception. ? preempted by any exception other than reset. hard fault a hard fault is an exception that occurs because of an error during exception processing, or because an exception cannot be managed by any other exception mechanism. hard faults have a fixed priority of -1, meaning they have higher priority than any exception with configurable priority. memory management fault (memmanage) a memory management fault is an exception that occurs because of a memory protection related fault. the mpu or the fixed memory protection constraints determines this fault, for both instruction and data memory transactions. this fault is used to abort instruction accesses to execute never (xn) memory regions, even if the mpu is disabled. bus fault a bus fault is an exception that occurs because of a memory related fault for an instruction or data memory transaction. this might be from an error detected on a bus in the memory system. usage fault a usage fault is an exception that occurs because of a fault related to an instruction execution. this includes: ? an undefined instruction. ? an illegal unaligned access. ? an invalid state on instruction execution. ? an error on exception return. the following can cause a usage fault when the core is configured to report them: ? an unaligned address on word and halfword memory access. ? a division by zero. svcall a supervisor call (svc) is an exception that is triggered by the svc instruction. in an os environment, applications can use svc instructions to access os kernel functions and device drivers. pendsv pendsv is an interrupt-driven request for system-level service. in an os environment, use pendsv for context switching when no other exception is active. systick a systick exception is an exception the system timer generates when it reaches zero. software can also generate a systick exception. in an os environment, the processor can use this exception as system tick. interrupt (irq) a interrupt, or irq, is an exception signalled by a peripheral, or generated by a software request. all interrupts are asynchronous to instruction execution. in the system, peripherals use interrupts to communicate with the processor.
72 sam4cp [datasheet] 43051e?atpl?08/14 notes: 1. to simplify the software layer, the cmsis only uses irq numbers and therefore uses negative values for exceptions other than interrupts. the ipsr returns the exception number, see ?interrupt program status register? . 2. see ?vector table? for more information. 3. see ?system handler priority registers? . 4. see ?interrupt priority registers? . 5. increasing in steps of 4. for an asynchronous exception, other than reset, the processor can execute another instruction between when the exception is triggered and when the processor enters the exception handler. privileged software can disable the exceptions that table 12-9 shows as having configurable priority, see: ? ?system handler control and state register? . ? ?interrupt clear-enable registers? . for more information about hard faults, memory management faults, bus faults, and usage faults, see ?fault handling? . 12.4.3.3 exception handlers the processor handles exceptions using: ? interrupt service routines (isrs) interrupts irq0 to irq40 are the exceptions handled by isrs. ? fault handlers hard fault, memory management fault, usage fault, bus fault are fault exceptions handled by the fault handlers. ? system handlers nmi, pendsv, svcall systick, and the fault exceptions are all system exceptions that are handled by system handlers. table 12-9. properties of the different exception types exception number (1) irq number (1) exception type priority vector address or offset (2) activation 1 - reset -3, the highest 0x00000004 asynchronous 2 -14 nmi -2 0x00000008 asynchronous 3 -13 hard fault -1 0x0000000c - 4 -12 memory management fault configurable (3) 0x00000010 synchronous 5 -11 bus fault configurable (3) 0x00000014 synchronous when precise, asynchronous when imprecise 6 -10 usage fault configurable (3) 0x00000018 synchronous 7 - 10 - - - reserved - 11 -5 svcall configurable (3) 0x0000002c synchronous 12 - 13 - - - reserved - 14 -2 pendsv configurable (3) 0x00000038 asynchronous 15 -1 systick configurable (3) 0x0000003c asynchronous 16 and above 0 and above interrupt (irq) configurable (4) 0x00000040 and above (5) asynchronous
73 sam4cp [datasheet] 43051e?atpl?08/14 12.4.3.4 vector table the vector table contains the reset value of the stack pointer, and the start addresses, also called exception vectors, for all exception handlers. figure 12-6 shows the order of the exception vectors in the vector table. the least-significant bit of each vector must be 1, indicating that the exception handler is thumb code. figure 12-6. vector table on system reset, the vector table is fixed at address 0x00000000. privileged software can write to the scb_vtor regis- ter to relocate the vector table start address to a different memory location, in the range 0x00000080 to 0x3fffff80, see ?vector table offset register? . 12.4.3.5 exception priorities as table 12-9 shows, all exceptions have an associated priority, with: ? a lower priority value indicating a higher priority. ? configurable priorities for all exceptions except reset, hard fault and nmi. if the software does not configure any priorities, then all ex ceptions with a configurable priority have a priority of 0. for information about configuring exception priorities see ?system handler priority registers? , and ?interrupt priority registers? . note: configurable priority values are in the range 0-15. this means that the reset, hard fault, and nmi exceptions, with fixed negative priority values, always have higher priority than any other exception. for example, assigning a higher priority value to irq[0] and a lower priority value to irq[1] means that irq[1] has higher priority than irq[0]. if both irq[1] and irq[0] are asserted, irq[1] is processed before irq[0]. if multiple pending exceptions have the same priority, the pending exception with the lowest exception number takes pre- cedence. for example, if both irq[0] and irq[1] are pending and have the same priority, then irq[0] is processed before irq[1]. initial sp value reset hard fault nmi memory management fault usage fault bus fault 0x0000 0x0004 0x0008 0x000c 0x0010 0x0014 0x0018 reserved svcall pendsv reserved for debug systick irq0 reserved 0x002c 0x0038 0x003c 0x0040 offset exception number 2 3 4 5 6 11 12 14 15 16 18 13 7 10 1 vector . . . 8 9 irq1 irq2 0x0044 irq239 17 0x0048 0x004c 255 . . . . . . 0x03fc irq number -14 -13 -12 -11 -10 -5 -2 -1 0 2 1 239
74 sam4cp [datasheet] 43051e?atpl?08/14 when the processor is executing an exception handler, the exception handler is preempted if a higher priority exception occurs. if an exception occurs with the same priority as the exception being handled, the handler is not preempted, irrespective of the exception number. however, the status of the new interrupt changes to pending. 12.4.3.6 interrupt priority grouping to increase priority control in systems with interrupts, the nvic supports priority grouping. this divides each interrupt priority register entry into two fields: ? an upper field that defines the group priority. ? a lower field that defines a subpriority within the group. only the group priority determines preemption of interrupt exceptions. when the processor is executing an interrupt exception handler, another interrupt with the same group priority as the interrupt being handled does not preempt the handler. if multiple pending interrupts have the same group priority, the subpriority field determines the order in which they are processed. if multiple pending interrupts have the same group priority and subpriority, the interrupt with the lowest irq number is processed first. for information about splitting the interrupt priority fields into group priority and subpriority, see ?application interrupt and reset control register? . 12.4.3.7 exception entry and return descriptions of exception handling use the following terms: preemption when the processor is executing an exception handler, an ex ception can preempt the exception handler if its priority is higher than the priority of the exception being handled. see ?interrupt priority grouping? for more information about preemption by an interrupt. when one exception preempts another, the exceptions are called nested exceptions. see ?exception entry? more information. return this occurs when the exception handler is completed, and: ? there is no pending exception with sufficient priority to be serviced. ? the completed exception handler was not handling a late-arriving exception. the processor pops the stack and restores the processor state to the state it had before the interrupt occurred. see ?exception return? for more information. tail-chaining this mechanism speeds up exception servicing. on completion of an exception handler, if there is a pending exception that meets the requirements for exception entry, the stack pop is skipped and control transfers to the new exception handler. late-arriving this mechanism speeds up preemption. if a higher priority exception occurs during state saving for a previous exception, the processor switches to handle the higher priority exception and initiates the vector fetch for that exception. state saving is not affected by late arrival because the state saved is the same for both exceptions. therefore the state saving continues uninterrupted. the processor can accept a late arriving exception until the first instruction of the exception handler of the original exception enters the execute stage of the processor. on return from the exception handler of the late-arriving exception, the normal tail-chaining rules apply. exception entry an exception entry occurs when there is a pending exception with sufficient priority and either the processor is in thread mode, or the new exception is of a higher priority than the exception being handled, in which case the new exception preempts the original exception.
75 sam4cp [datasheet] 43051e?atpl?08/14 when one exception preempts another, the exceptions are nested. sufficient priority means that the exception has more priority than any limits set by the mask registers, see ?exception mask registers? . an exception with less priority than this is pending but is not handled by the processor. when the processor takes an exception, unless the exception is a tail-chained or a late-arriving exception, the processor pushes information onto the current stack. this operation is referred as stacking and the structure of eight data words is referred to as stack frame . when using floating-point routines, the cortex-m4 processor automatically stacks the architected floating-point state on exception entry. figure 12-1 shows the cortex-m4 stack frame layout when floating-point state is preserved on the stack as the result of an interrupt or an exception. note: where stack space for floating-point state is not allocated, the stack frame is the same as that of armv7-m implementations without an fpu. figure 12-1 shows this stack frame also. figure 12-7. exception stack frame immediately after stacking, the stack pointer indicates the lowest address in the stack frame. the alignment of the stack frame is controlled via the stkalign bit of the configuration control register (ccr). the stack frame includes the return address. this is the address of the next instruction in the interrupted program. this value is restored to the pc at exception return so that the interrupted program resumes. in parallel to the stacking operation, the processor performs a vector fetch that reads the exception handler start address from the vector table. when stacking is complete, the processor starts executing the exception handler. at the same time, the processor writes an exc_return value to the lr. this indicates which stack pointer corresponds to the stack frame and what operation mode the processor was in before the entry occurred. if no higher priority exception occurs during the exception entry, the processor starts executing the exception handler and automatically changes the status of the corresponding pending interrupt to active. if another higher priority exception occurs during the exception entry, the processor starts executing the exception handler for this exception and does not change the pending status of the earlier exception. this is the late arrival case. pre-irq top of stack xpsr pc lr r12 r3 r2 r1 r0 {aligner} irq top of stack decreasing memory address xpsr pc lr r12 r3 r2 r1 r0 s7 s6 s5 s4 s3 s2 s1 s0 s9 s8 fpscr s15 s14 s13 s12 s11 s10 {aligner} irq top of stack ... exception frame with floating-point storage exception frame without floating-point storage pre-irq top of stack ...
76 sam4cp [datasheet] 43051e?atpl?08/14 exception return an exception return occurs when the processor is in handler mode and executes one of the following instructions to load the exc_return value into the pc: ? an ldm or pop instruction that loads the pc. ? an ldr instruction with the pc as the destination. ? a bx instruction using any register. exc_return is the value loaded into the lr on exception entry. the exception mechanism relies on this value to detect when the processor has completed an exception handler. the lowest five bits of this value provide information on the return stack and processor mode. table 12-10 shows the exc_return values with a description of the exception return behavior. all exc_return values have bits[31:5] set to one. when this value is loaded into the pc, it indicates to the processor that the exception is complete, and the processor initiates the appropriate exception return sequence. 12.4.3.8 fault handling faults are a subset of the exceptions, see ?exception model? . the following generate a fault: ? a bus error on: ? an instruction fetch or vector table load. ? a data access. ? an internally-detected error such as an undefined instruction. ? an attempt to execute an instruction from a memory region marked as non-executable (xn) . ? a privilege violation or an attempt to access an unmanaged region causing an mpu fault. fault types table 12-11 shows the types of fault, the handler used for the fault, the corresponding fault status register, and the regis- ter bit that indicates that the fault has occurred. see ?configurable fault status register? for more information about the fault status registers. table 12-10. exception return behavior exc_return[31:0] description 0xfffffff1 return to handler mode, exception return uses non-floating-point state from the msp and execution uses msp after return. 0xfffffff9 return to thread mode, exception return uses state from msp and execution uses msp after return. 0xfffffffd return to thread mode, exception return uses state from the psp and execution uses psp after return. 0xffffffe1 return to handler mode, exception return uses floating-point-state from msp and execution uses msp after return. 0xffffffe9 return to thread mode, exception return uses floating-point state from msp and execution uses msp after return. 0xffffffed return to thread mode, exception return uses floating-point state from psp and execution uses psp after return. table 12-11. faults fault handler bit name fault status register bus error on a vector read hard fault vecttbl ?hard fault status register? fault escalated to a hard fault forced
77 sam4cp [datasheet] 43051e?atpl?08/14 notes: 1. occurs on an access to an xn region even if the processor does not include an mpu or the mpu is disabled. 2. attempt to use an instruction set other than the thumb instruction set, or return to a non load/store-multiple instruction with ici continuation. 3. only present in a cortex-m4f device. fault escalation and hard faults all faults exceptions except for hard fault have configurable exception priority, see ?system handler priority registers? . the software can disable the execution of the handlers for these faults, see ?system handler control and state register? . usually, the exception priority, together with the values of the exception mask registers, determines whether the processor enters the fault handler, and whether a fault handler can preempt another fault handler, as described in ?exception model? . in some situations, a fault with configurable priority is treated as a hard fault. this is called priority escalation , and the fault is described as escalated to hard fault . escalation to hard fault occurs when: ? a fault handler causes the same kind of fault as the one it is servicing. this escalation to hard fault occurs because a fault handler cannot preempt itself; it must have the same priority as the current priority level. ? a fault handler causes a fault with the same or lower priority as the fault it is servicing. this is because the handler for the new fault cannot preempt the currently executing fault handler. ? an exception handler causes a fault for which the priority is the same as or lower than the currently executing exception. ? a fault occurs and the handler for that fault is not enabled. if a bus fault occurs during a stack push when entering a bus fault handler, the bus fault does not escalate to a hard fault. this means that if a corrupted stack causes a fault, the fault handler executes even though the stack push for the handler failed. the fault handler operates but the stack contents are corrupted. note: only reset and nmi can preempt the fixed priority hard fault. a hard fault can preempt any exception other than reset, nmi, or another hard fault. mpu or default memory map mismatch: memory management fault -- on instruction access iaccviol (1) ?mmfsr: memory management fault status subregister? on data access daccviol (2) during exception stacking mstkerr during exception unstacking munstkerr during lazy floating-point state preservation mlsperr (3) bus error: bus fault -- during exception stacking stkerr ?bfsr: bus fault status subregister? during exception unstacking unstkerr during instruction prefetch ibuserr during lazy floating-point state preservation lsperr (3) precise data bus error preciserr imprecise data bus error impreciserr attempt to access a coprocessor usage fault nocp ?ufsr: usage fault status subregister? undefined instruction undefinstr attempt to enter an invalid instruction set state invstate invalid exc_return value invpc illegal unaligned load or store unaligned divide by 0 divbyzero table 12-11. faults (continued) fault handler bit name fault status register
78 sam4cp [datasheet] 43051e?atpl?08/14 fault status registers and fault address registers the fault status registers indicate the cause of a fault. for bus faults and memory management faults, the fault address register indicates the address accessed by the operation that caused the fault, as shown in table 12-12 . lockup the processor enters a lockup state if a hard fault occurs when executing the nmi or hard fault handlers. when the pro- cessor is in lockup state, it does not execute any instructions. the processor remains in lockup state until either: ? it is reset. ? an nmi occurs. ? it is halted by a debugger. note: if the lockup state occurs from the nmi handler, a subsequent nmi does not cause the processor to leave the lockup state. 12.5 power management the cortex-m4 processor sleep modes reduce the power consumption: ? sleep mode stops the processor clock. ? deep sleep mode stops the system clock and switches off the pll and flash memory. the sleepdeep bit of the scr selects which sleep mode is used; see ?system control register? . this section describes the mechanisms for entering sleep mode, and the conditions for waking up from sleep mode. 12.5.1 entering sleep mode this section describes the mechanisms software can use to put the processor into sleep mode. the system can generate spurious wakeup events, for example a debug operation wakes up the processor. therefore, the software must be able to put the processor back into sleep mode after such an event. a program might have an idle loop to put the processor back to sleep mode. 12.5.1.1 wait for interrupt the wait for interrupt instruction, wfi, causes immediate entry to sleep mode. when the processor executes a wfi instruction it stops executing instructions and enters sleep mode. see ?wfi? for more information. 12.5.1.2 wait for event the wait for event instruction, wfe, causes entry to sleep mode conditional on the value of an one-bit event register. when the processor executes a wfe instruction, it checks this register: ? if the register is 0, the processor stops executing instructions and enters sleep mode. ? if the register is 1, the processor clears the register to 0 and continues executing instructions without entering sleep mode. see ?wfe? for more information. table 12-12. fault status and fault address registers handler status register name address register name register description hard fault scb_hfsr - ?hard fault status register? memory management fault mmfsr scb_mmfar ?mmfsr: memory management fault status subregister? ?memmanage fault address register? bus fault bfsr scb_bfar ?bfsr: bus fault status subregister? ?bus fault address register? usage fault ufsr - ?ufsr: usage fault status subregister?
79 sam4cp [datasheet] 43051e?atpl?08/14 12.5.1.3 sleep-on-exit if the sleeponexit bit of the scr is set to 1 when the proc essor completes the execution of an exception handler, it returns to thread mode and immediately enters sleep mode. use this mechanism in applications that only require the processor to run when an exception occurs. 12.5.2 wakeup from sleep mode the conditions for the processor to wake up depend on the mechanism that cause it to enter sleep mode. 12.5.2.1 wakeup from wfi or sleep-on-exit normally, the processor wakes up only when it detects an exception with sufficient priority to cause exception entry. some embedded systems might have to execute system restore tasks after the processor wakes up, and before it executes an interrupt handler. to achieve this, set the primask bit to 1 and the faultmask bit to 0. if an interrupt arrives that is enabled and has a higher priority than the current exception priority, the processor wakes up but does not execute the interrupt handler until the processor sets primask to zero. for more information about primask and faultmask, see ?exception mask registers? . 12.5.2.2 wakeup from wfe the processor wakes up if: ? it detects an exception with sufficient priority to cause an exception entry. ? it detects an external event signal. see ?external event input? . ? in a multiprocessor system, another processor in the system executes an sev instruction. in addition, if the sevonpend bit in the scr is set to 1, any new pending interrupt triggers an event and wakes up the processor, even if the interrupt is disa bled or has insufficient priority to caus e an exception entry. for more information about the scr, see ?system control register? . 12.5.2.3 external event input the processor provides an external event input signal. peripherals can drive this signal, either to wake the processor from wfe, or to set the internal wfe event register to 1 to indicate that the processor must not enter sleep mode on a later wfe instruction. see ?wait for event? for more information. 12.5.3 power management programming hints iso/iec c cannot directly generate the wfi and wfe instructions. the cmsis provides the following functions for these instructions: void __wfe(void) // wait for event void __wfi(void) // wait for interrupt
80 sam4cp [datasheet] 43051e?atpl?08/14 12.6 cortex-m4 instruction set 12.6.1 instruction set summary the processor implements a version of the thumb instruction set. table 12-13 lists the supported instructions. ? angle brackets, <>, enclose alternative forms of the operand. ? braces, {}, enclose optional operands. ? the operands column is not exhaustive. ? op2 is a flexible second operand that can be either a register or a constant. ? most instructions can use an optional condition code suffix. for more information on the instructions and operands, see the instruction descriptions. table 12-13. cortex-m4 instructions mnemonic operands description flags adc, adcs {rd,} rn, op2 add with carry n,z,c,v add, adds {rd,} rn, op2 add n,z,c,v add, addw {rd,} rn, #imm12 add n,z,c,v adr rd, label load pc-relative address - and, ands {rd,} rn, op2 logical and n,z,c asr, asrs rd, rm, arithmetic shift right n,z,c b label branch - bfc rd, #lsb, #width bit field clear - bfi rd, rn, #lsb, #width bit field insert - bic, bics {rd,} rn, op2 bit clear n,z,c bkpt #imm breakpoint - bl label branch with link - blx rm branch indirect with link - bx rm branch indirect - cbnz rn, label compare and branch if non zero - cbz rn, label compare and branch if zero - clrex - clear exclusive - clz rd, rm count leading zeros - cmn rn, op2 compare negative n,z,c,v cmp rn, op2 compare n,z,c,v cpsid i change processor state, disable interrupts - cpsie i change processor state, enable interrupts - dmb - data memory barrier - dsb - data synchronization barrier - eor, eors {rd,} rn, op2 exclusive or n,z,c isb - instruction synchronization barrier - it - if-then condition block - ldm rn{!}, reglist load multiple registers, increment after -
81 sam4cp [datasheet] 43051e?atpl?08/14 ldmdb, ldmea rn{!}, reglist load multiple registers, decrement before - ldmfd, ldmia rn{!}, reglist load multiple registers, increment after - ldr rt, [rn, #offset] load register with word - ldrb, ldrbt rt, [rn, #offset] load register with byte - ldrd rt, rt2, [rn, #offset] load register with two bytes - ldrex rt, [rn, #offset] load register exclusive - ldrexb rt, [rn] load register exclusive with byte - ldrexh rt, [rn] load register exclusive with halfword - ldrh, ldrht rt, [rn, #offset] load register with halfword - ldrsb, drsbt rt, [rn, #offset] load register with signed byte - ldrsh, ldrsht rt, [rn, #offset] load register with signed halfword - ldrt rt, [rn, #offset] load register with word - lsl, lsls rd, rm, logical shift left n,z,c lsr, lsrs rd, rm, logical shift right n,z,c mla rd, rn, rm, ra multiply with accumulate, 32-bit result - mls rd, rn, rm, ra multiply and subtract, 32-bit result - mov, movs rd, op2 move n,z,c movt rd, #imm16 move top - movw, mov rd, #imm16 move 16-bit constant n,z,c mrs rd, spec_reg move from special register to general register - msr spec_reg, rm move from general register to special register n,z,c,v mul, muls {rd,} rn, rm multiply, 32-bit result n,z mvn, mvns rd, op2 move not n,z,c nop - no operation - orn, orns {rd,} rn, op2 logical or not n,z,c orr, orrs {rd,} rn, op2 logical or n,z,c pkhtb, pkhbt {rd,} rn, rm, op2 pack halfword - pop reglist pop registers from stack - push reglist push registers onto stack - qadd {rd,} rn, rm saturating double and add q qadd16 {rd,} rn, rm saturating add 16 - qadd8 {rd,} rn, rm saturating add 8 - qasx {rd,} rn, rm saturating add and subtract with exchange - qdadd {rd,} rn, rm saturating add q qdsub {rd,} rn, rm saturating double and subtract q qsax {rd,} rn, rm saturating subtract and add with exchange - qsub {rd,} rn, rm saturating subtract q table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
82 sam4cp [datasheet] 43051e?atpl?08/14 qsub16 {rd,} rn, rm saturating subtract 16 - qsub8 {rd,} rn, rm saturating subtract 8 - rbit rd, rn reverse bits - rev rd, rn reverse byte order in a word - rev16 rd, rn reverse byte order in each halfword - revsh rd, rn reverse byte order in bottom halfword and sign extend - ror, rors rd, rm, rotate right n,z,c rrx, rrxs rd, rm rotate right with extend n,z,c rsb, rsbs {rd,} rn, op2 reverse subtract n,z,c,v sadd16 {rd,} rn, rm signed add 16 ge sadd8 {rd,} rn, rm signed add 8 and subtract with exchange ge sasx {rd,} rn, rm signed add ge sbc, sbcs {rd,} rn, op2 subtract with carry n,z,c,v sbfx rd, rn, #lsb, #width signed bit field extract - sdiv {rd,} rn, rm signed divide - sel {rd,} rn, rm select bytes - sev - send event - shadd16 {rd,} rn, rm signed halving add 16 - shadd8 {rd,} rn, rm signed halving add 8 - shasx {rd,} rn, rm signed halving add and subtract with exchange - shsax {rd,} rn, rm signed halving subtract and add with exchange - shsub16 {rd,} rn, rm signed halving subtract 16 - shsub8 {rd,} rn, rm signed halving subtract 8 - smlabb, smlabt, smlatb, smlatt rd, rn, rm, ra signed multiply accumulate long (halfwords) q smlad, smladx rd, rn, rm, ra signed multiply accumulate dual q smlal rdlo, rdhi, rn, rm signed multiply with accumulate (32 x 32 + 64), 64-bit result - smlalbb, smlalbt, smlaltb, smlaltt rdlo, rdhi, rn, rm signed multiply accumulate long, halfwords - smlald, smlaldx rdlo, rdhi, rn, rm signed multiply accumulate long dual - smlawb, smlawt rd, rn, rm, ra signed multiply accumulate, word by halfword q smlsd rd, rn, rm, ra signed multiply subtract dual q smlsld rdlo, rdhi, rn, rm signed multiply subtract long dual - smmla rd, rn, rm, ra signed most significant word multiply accumulate - smmls, smmlr rd, rn, rm, ra signed most significant word multiply subtract - smmul, smmulr {rd,} rn, rm signed most significant word multiply - smuad {rd,} rn, rm signed dual multiply add q table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
83 sam4cp [datasheet] 43051e?atpl?08/14 smulbb, smulbt smultb, smultt {rd,} rn, rm signed multiply (halfwords) - smull rdlo, rdhi, rn, rm signed multiply (32 x 32), 64-bit result - smulwb, smulwt {rd,} rn, rm signed multiply word by halfword - smusd, smusdx {rd,} rn, rm signed dual multiply subtract - ssat rd, #n, rm {,shift #s} signed saturate q ssat16 rd, #n, rm signed saturate 16 q ssax {rd,} rn, rm signed subtract and add with exchange ge ssub16 {rd,} rn, rm signed subtract 16 - ssub8 {rd,} rn, rm signed subtract 8 - stm rn{!}, reglist store multiple registers, increment after - stmdb, stmea rn{!}, reglist store multiple registers, decrement before - stmfd, stmia rn{!}, reglist store multiple registers, increment after - str rt, [rn, #offset] store register word - strb, strbt rt, [rn, #offset] store register byte - strd rt, rt2, [rn, #offset] store register two words - strex rd, rt, [rn, #offset] store register exclusive - strexb rd, rt, [rn] store register exclusive byte - strexh rd, rt, [rn] store register exclusive halfword - strh, strht rt, [rn, #offset] store register halfword - strt rt, [rn, #offset] store register word - sub, subs {rd,} rn, op2 subtract n,z,c,v sub, subw {rd,} rn, #imm12 subtract n,z,c,v svc #imm supervisor call - sxtab {rd,} rn, rm,{,ror #} extend 8 bits to 32 and add - sxtab16 {rd,} rn, rm,{,ror #} dual extend 8 bits to 16 and add - sxtah {rd,} rn, rm,{,ror #} extend 16 bits to 32 and add - sxtb16 {rd,} rm {,ror #n} signed extend byte 16 - sxtb {rd,} rm {,ror #n} sign extend a byte - sxth {rd,} rm {,ror #n} sign extend a halfword - tbb [rn, rm] table branch byte - tbh [rn, rm, lsl #1] table branch halfword - teq rn, op2 test equivalence n,z,c tst rn, op2 test n,z,c uadd16 {rd,} rn, rm unsigned add 16 ge uadd8 {rd,} rn, rm unsigned add 8 ge usax {rd,} rn, rm unsigned subtract and add with exchange ge table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
84 sam4cp [datasheet] 43051e?atpl?08/14 uhadd16 {rd,} rn, rm unsigned halving add 16 - uhadd8 {rd,} rn, rm unsigned halving add 8 - uhasx {rd,} rn, rm unsigned halving add and subtract with exchange - uhsax {rd,} rn, rm unsigned halving subtract and add with exchange - uhsub16 {rd,} rn, rm unsigned halving subtract 16 - uhsub8 {rd,} rn, rm unsigned halving subtract 8 - ubfx rd, rn, #lsb, #width unsigned bit field extract - udiv {rd,} rn, rm unsigned divide - umaal rdlo, rdhi, rn, rm unsigned multiply accumulate accumulate long (32 x 32 + 32 +32), 64-bit result - umlal rdlo, rdhi, rn, rm unsigned multiply with accumulate (32 x 32 + 64), 64-bit result - umull rdlo, rdhi, rn, rm unsigned multiply (32 x 32), 64-bit result - uqadd16 {rd,} rn, rm unsigned saturating add 16 - uqadd8 {rd,} rn, rm unsigned saturating add 8 - uqasx {rd,} rn, rm unsigned saturating add and subtract with exchange - uqsax {rd,} rn, rm unsigned saturating subtract and add with exchange - uqsub16 {rd,} rn, rm unsigned saturating subtract 16 - uqsub8 {rd,} rn, rm unsigned saturating subtract 8 - usad8 {rd,} rn, rm unsigned sum of absolute differences - usada8 {rd,} rn, rm, ra unsigned sum of absolute differences and accumulate - usat rd, #n, rm {,shift #s} unsigned saturate q usat16 rd, #n, rm unsigned saturate 16 q uasx {rd,} rn, rm unsigned add and subtract with exchange ge usub16 {rd,} rn, rm unsigned subtract 16 ge usub8 {rd,} rn, rm unsigned subtract 8 ge uxtab {rd,} rn, rm,{,ror #} rotate, extend 8 bits to 32 and add - uxtab16 {rd,} rn, rm,{,ror #} rotate, dual extend 8 bits to 16 and add - uxtah {rd,} rn, rm,{,ror #} rotate, unsigned extend and add halfword - uxtb {rd,} rm {,ror #n} zero extend a byte - uxtb16 {rd,} rm {,ror #n} unsigned extend byte 16 - uxth {rd,} rm {,ror #n} zero extend a halfword - vabs.f32 sd, sm floating-point absolute - vadd.f32 {sd,} sn, sm floating-point add - vcmp.f32 sd, compare two floating-point registers, or one floating-point register and zero fpscr vcmpe.f32 sd, compare two floating-point registers, or one floating-point register and zero with invalid operation check fpscr table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
85 sam4cp [datasheet] 43051e?atpl?08/14 vcvt.s32.f32 sd, sm convert between floating-point and integer - vcvt.s16.f32 sd, sd, #fbits convert between floating-point and fixed point - vcvtr.s32.f32 sd, sm convert between floating-point and integer with rounding - vcvt.f32.f16 sd, sm converts half-precision value to single-precision - vcvtt.f32.f16 sd, sm converts single-precision register to half-precision - vdiv.f32 {sd,} sn, sm floating-point divide - vfma.f32 {sd,} sn, sm floating-point fused multiply accumulate - vfnma.f32 {sd,} sn, sm floating-point fused negate multiply accumulate - vfms.f32 {sd,} sn, sm floating-point fused multiply subtract - vfnms.f32 {sd,} sn, sm floating-point fused negate multiply subtract - vldm.f<32|64> rn{!}, list load multiple extension registers - vldr.f<32|64> , [rn] load an extension register from memory - vlma.f32 {sd,} sn, sm floating-point multiply accumulate - vlms.f32 {sd,} sn, sm floating-point multiply subtract - vmov.f32 sd, #imm floating-point move immediate - vmov sd, sm floating-point move register - vmov sn, rt copy arm core register to single precision - vmov sm, sm1, rt, rt2 copy 2 arm core registers to 2 single precision - vmov dd[x], rt copy arm core register to scalar - vmov rt, dn[x] copy scalar to arm core register - vmrs rt, fpscr move fpscr to arm core register or apsr n,z,c,v vmsr fpscr, rt move to fpscr from arm core register fpscr vmul.f32 {sd,} sn, sm floating-point multiply - vneg.f32 sd, sm floating-point negate - vnmla.f32 sd, sn, sm floating-point multiply and add - vnmls.f32 sd, sn, sm floating-point multiply and subtract - vnmul {sd,} sn, sm floating-point multiply - vpop list pop extension registers - vpush list push extension registers - vsqrt.f32 sd, sm calculates floating-point square root - vstm rn{!}, list floating-point register store multiple - vstr.f<32|64> sd, [rn] stores an extension register to memory - vsub.f<32|64> {sd,} sn, sm floating-point subtract - wfe - wait for event - wfi - wait for interrupt - table 12-13. cortex-m4 instructions (continued) mnemonic operands description flags
86 sam4cp [datasheet] 43051e?atpl?08/14 12.6.2 cmsis functions iso/iec cannot directly access some cortex-m4 instructions. this section describes intrinsic functions that can generate these instructions, provided by the cmis and that might be provided by a c compiler. if a c compiler does not support an appropriate intrinsic function, the user might have to use inline assembler to access some instructions. the cmsis provides the following intrinsic functions to generate instructions that iso/iec c code cannot directly access: the cmsis also provides a number of functions for accessing the special registers using mrs and msr instructions: table 12-14. cmsis functions to generate some cortex-m4 instructions instruction cmsis function cpsie i void __enable_irq(void) cpsid i void __disable_irq(void) cpsie f void __enable_fault_irq(void) cpsid f void __disable_fault_irq(void) isb void __isb(void) dsb void __dsb(void) dmb void __dmb(void) rev uint32_t __rev(uint32_t int value) rev16 uint32_t __rev16(uint32_t int value) revsh uint32_t __revsh(uint32_t int value) rbit uint32_t __rbit(uint32_t int value) sev void __sev(void) wfe void __wfe(void) wfi void __wfi(void) table 12-15. cmsis intrinsic functions to access the special registers special register access cmsis function primask read uint32_t __get_primask (void) write void __set_primask (uint32_t value) faultmask read uint32_t __get_faultmask (void) write void __set_faultmask (uint32_t value) basepri read uint32_t __get_basepri (void) write void __set_basepri (uint32_t value) control read uint32_t __get_control (void) write void __set_control (uint32_t value) msp read uint32_t __get_msp (void) write void __set_msp (uint32_t topofmainstack) psp read uint32_t __get_psp (void) write void __set_psp (uint32_t topofprocstack)
87 sam4cp [datasheet] 43051e?atpl?08/14 12.6.3 instruction descriptions 12.6.3.1 operands an instruction operand can be an arm register, a constant, or another instruction-specific parameter. instructions act on the operands and often store the result in a destination register. when there is a destination register in the instruction, it is usually specified before the operands. operands in some instructions are flexible, can either be a register or a constant. see ?flexible second operand? . 12.6.3.2 restrictions when using pc or sp many instructions have restrictions on whether the program counter (pc) or stack pointer (sp) for the operands or des- tination register can be used. see instruction descriptions for more information. note: bit[0] of any address written to the pc with a bx, blx, ldm, ldr, or pop instruction must be 1 for correct exe- cution, because this bit indicates the required instruction set, and the cortex-m4 processor only supports thumb instructions. 12.6.3.3 flexible second operand many general data processing instructions have a flexible second operan d. this is shown as operand2 in the descrip- tions of the syntax of each instruction. operand2 can be a: ? ?constant? . ? ?register with optional shift? . constant specify an operand2 constant in the form: # constant where constant can be: ? any constant that can be produced by shifting an 8-bit value left by any number of bits within a 32-bit word. ? any constant of the form 0x00xy00xy. ? any constant of the form 0xxy00xy00. ? any constant of the form 0xxyxyxyxy. note: in the constants shown above, x and y are hexadecimal digits. in addition, in a small number of instructions, constant can take a wider range of values. these are described in the indi- vidual instruction descriptions. when an operand2 constant is used with the instru ctions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to bit[31] of the constant, if the constant is greater than 255 and can be produced by shifting an 8-bit value. these instructions do not affect the carry flag if operand2 is any other constant. instruction substitution the assembler might be able to produce an equivalent instruction in cases where the user specifies a constant that is not permitted. for example, an assembler might assemble the instruction cmp rd , #0xfffffffe as the equivalent instruction cmn rd , #0x2. register with optional shift specify an operand2 register in the form: rm {, shift } where: rm is the register holding the data for the second operand. shift is an optional shift to be applied to rm . it can be one of: asr # n arithmetic shift right n bits, 1 ? n ? 32. lsl # n logical shift left n bits, 1 ? n ? 31.
88 sam4cp [datasheet] 43051e?atpl?08/14 lsr # n logical shift right n bits, 1 ? n ? 32. ror # n rotate right n bits, 1 ?? n ? 31. rrx rotate right one bit, with extend. - if omitted, no shift occurs, equivalent to lsl #0. if the user omits the shift, or specifies lsl #0, the instruction uses the value in rm . if the user specifies a shift, the shift is applied to the value in rm , and the resulting 32-bit value is used by the instruction. however, the contents in the register rm remains unchanged. specifying a register with shift also updates the carry flag when used with certain instructions. for information on the shift operations and how they affect the carry flag, see ?flexible second operand? 12.6.3.4 shift operations register shift operations move the bits in a register left or right by a spec ified number of bits, the shift length . register shift can be performed: ? directly by the instructions asr, lsr, lsl, ror, and rrx, and the result is written to a destination register. ? during the calculation of operand2 by the instructions that specify the second operand as a register with shift. see ?flexible second operand? . the result is used by the instruction. the permitted shift lengths depend on the shift type and the inst ruction. if the shift length is 0, no shift occurs. register shift operations update the carry flag except when the specified shift length is 0. the following subsections describe the various shift operations and how they affect the carry flag. in these descriptions, rm is the register containing the value to be shifted, and n is the shift length. asr arithmetic shift right by n bits moves the left-hand 32-n bits of the register, rm , to the right by n places, into the right-hand 32-n bits of the result. and it copies the original bit[31] of the register into the left-hand n bits of the result. see figure 12- 8 . the asr #n operation can be used to divide the value in the register rm by 2 n , with the result being rounded towards negative-infinity. when the instruction is asrs or when asr #n is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to the last bit shifted out, bit[ n -1], of the register rm . ? if n is 32 or more, then all the bits in the result are set to the value of bit[31] of rm . ? if n is 32 or more and the carry flag is updated, it is updated to the value of bit[31] of rm . figure 12-8. asr #3 lsr logical shift right by n bits moves the left-hand 32-n bits of the register rm, to the right by n places, into the right-hand 32-n bits of the result. and it sets the left-hand n bits of the result to 0. see figure 12-9 . the lsr #n operation can be used to divide the value in the register rm by 2 n , if the value is regarded as an unsigned integer. when the instruction is lsrs or when lsr #n is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to the last bit shifted out, bit[n-1], of the register rm. ? if n is 32 or more, then all the bits in the result are cleared to 0. ? if n is 33 or more and the carry flag is updated, it is updated to 0. carry flag 0 31 5 4 3 2 1
89 sam4cp [datasheet] 43051e?atpl?08/14 figure 12-9. lsr #3 lsl logical shift left by n bits moves the right-hand 32-n bits of the register rm, to the left by n places, into the left-hand 32-n bits of the result; and it sets the right-hand n bits of the result to 0. see figure 12-10 . the lsl #n operation can be used to multiply the value in the register rm by 2 n , if the value is regarded as an unsigned integer or a two?s complement signed integer. overflow can occur without warning. when the instruction is lsls or when lsl #n, with non-zero n , is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to the last bit shifted out, bit[32- n ], of the register rm . these instructions do not affect the carry flag when used with lsl #0. ? if n is 32 or more, then all the bits in the result are cleared to 0. ? if n is 33 or more and the carry flag is updated, it is updated to 0. figure 12-10. lsl #3 ror rotate right by n bits moves the left-hand 32- n bits of the register rm , to the right by n places, into the right-hand 32- n bits of the result; and it moves the right-hand n bits of the register into the left-hand n bits of the result. see figure 12-11 . when the instruction is rors or when ror # n is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to the last bit rotation, bit[ n -1], of the register rm . ? if n is 32, then the value of the result is same as the value in rm , and if the carry flag is updated, it is updated to bit[31] of rm . ? ror with shift length, n , more than 32 is the same as ror with shift length n -32. figure 12-11. ror #3 carry flag 0 31 0 5 4 3 2 1 0 0 0 31 0 5 4 3 2 1 0 0 carry flag carry flag 0 31 5 4 3 2 1
90 sam4cp [datasheet] 43051e?atpl?08/14 rrx rotate right with extend moves the bits of the register rm to the right by one bit; and it copies the carry flag into bit[31] of the result. see figure 12-12 . when the instruction is rrxs or when rrx is used in operand2 with the instructions movs, mvns, ands, orrs, orns, eors, bics, teq or tst, the carry flag is updated to bit[0] of the register rm . figure 12-12. rrx 12.6.3.5 address alignment an aligned access is an operation where a word-aligned address is used for a word, dual word, or multiple word access, or where a halfword-aligned address is used for a halfword access. byte accesses are always aligned. the cortex-m4 processor supports unaligned access only for the following instructions: ? ldr, ldrt. ? ldrh, ldrht. ? ldrsh, ldrsht. ? str, strt. ? strh, strht. all other load and store instructions generate a usage fault exception if they perform an unaligned access, and therefore their accesses must be address-aligned. for more information about usage faults, see ?fault handling? . unaligned accesses are usually slower than aligned accesses. in addition, some memory regions might not support unaligned accesses. therefore, arm recommends that progra mmers ensure that accesses are aligned. to avoid acci- dental generation of unaligned accesses, use the unalign_trp bit in the configuration and control register to trap all unaligned accesses, see ?configuration and control register? . 12.6.3.6 pc-relative expressions a pc-relative expression or label is a symbol that represents the address of an instruction or literal data. it is represented in the instruction as the pc value plus or minus a numeric offset. the assembler calculates the required offset from the label and the address of the current instruction. if the offset is too big, the assembler produces an error. ? for b, bl, cbnz, and cbz instructions, the value of the pc is the address of the current instruction plus 4 bytes. ? for all other instructions that use labels, the value of the pc is the address of the current instruction plus 4 bytes, with bit[1] of the result cleared to 0 to make it word-aligned. ? your assembler might permit other syntaxes for pc-relative expressions, such as a label plus or minus a number, or an expression of the form [pc, #number]. 12.6.3.7 conditional execution most data processing instructions can optiona lly update the condit ion flags in the application program status register (apsr) according to the result of the operation, see ?application program status register? . some instructions update all flags, and some only update a subset. if a flag is not updated, the original value is preserved. see the instruction descrip- tions for the flags they affect. an instruction can be executed conditionally, based on the condition flags set in another instruction, either: ? immediately after the instruction that updated the flags. ? after any number of intervening instructions that have not updated the flags. carry flag 0 31 1 30
91 sam4cp [datasheet] 43051e?atpl?08/14 conditional execution is available by using conditional branches or by adding condition code suffixes to instructions. see table 12-16 for a list of the suffixes to add to instructions to make them conditional instructions. the condition code suffix enables the processor to test a condition based on the flags. if the condition test of a conditional instruction fails, the instruction: ? does not execute. ? does not write any value to its destination register. ? does not affect any of the flags. ? does not generate any exception. conditional instructions, except for conditional branches , must be inside an if-then instruction block. see ?it? for more information and restrictions when using the it instruction. depending on the vendor, the assembler might automatically insert an it instruction if there are conditional instructions outside the it block. the cbz and cbnz instructions are used to compare the value of a register against zero and branch on the result. this section describes: ? ?condition flags? . ? ?condition code suffixes? . condition flags the apsr contains the following condition flags: n set to 1 when the result of the operation was negative, cleared to 0 otherwise. z set to 1 when the result of the operation was zero, cleared to 0 otherwise. c set to 1 when the operation resulted in a carry, cleared to 0 otherwise. v set to 1 when the operation caused overflow, cleared to 0 otherwise. for more information about the apsr, see ?program status register? . a carry occurs: ? if the result of an addition is greater than or equal to 2 32 . ? if the result of a subtraction is positive or zero. ? as the result of an inline barrel shifter operation in a move or logical instruction. an overflow occurs when the sign of the result, in bit[31] , does not match the sign of the result, had the operation been performed at infinite precision, for example: ? if adding two negative values results in a positive value. ? if adding two positive values results in a negative value. ? if subtracting a positive value from a negative value generates a positive value. ? if subtracting a negative value from a positive value generates a negative value. the compare operations are identical to subtracting, for cmp, or adding, for cm n, except that the result is discarded. see the instruction descriptions for more information. note: most instructions update the status flags only if the s suffix is specified. see the instruction descriptions for more information. condition code suffixes the instructions that can be conditional have an optional condition code, shown in syntax descriptions as {cond}. condi- tional execution requires a preceding it instruction. an instruction with a condition code is only executed if the condition code flags in the apsr meet the specified condition. table 12-16 shows the condition codes to use. a conditional execution can be used with the it instruction to reduce the number of branch instructions in code.
92 sam4cp [datasheet] 43051e?atpl?08/14 table 12-16 also shows the relationship between condition code suffixes and the n, z, c, and v flags. absolute value the example below shows the use of a conditional instruction to find the absolute value of a number. r0 = abs(r1). movs r0, r1 ; r0 = r1, setting flags it mi ; it instruction for the negative condition rsbmi r0, r1, #0 ; if negative, r0 = -r1 compare and update value the example below shows the use of conditional instructions to update the value of r4 if the signed values r0 is greater than r1 and r2 is greater than r3. cmp r0, r1 ; compare r0 and r1, setting flags itt gt ; it instruction for the two gt conditions cmpgt r2, r3 ; if 'greater than', compare r2 and r3, setting flags movgt r4, r5 ; if still 'greater than', do r4 = r5 12.6.3.8 instruction width selection there are many instructions that can generate either a 16-bit encoding or a 32-bit encoding depending on the operands and destination register specified. for some of these instructions, the user can force a specific instruction size by using an instruction width suffix. the .w suffix forces a 32-bit instruction encoding. the .n suffix forces a 16-bit instruction encoding. if the user specifies an instruction width suffix and the assembler cannot generate an instruction encoding of the requested width, it generates an error. note: in some cases, it might be necessary to specify the .w suffix, for example if the operand is the label of an instruction or literal data, as in the case of branch instructions. this is because the assembler might not auto- matically generate the right size encoding. table 12-16. condition code suffixes suffix flags meaning eq z = 1 equal ne z = 0 not equal cs or hs c = 1 higher or same, unsigned ? cc or lo c = 0 lower, unsigned < mi n = 1 negative pl n = 0 positive or zero vs v = 1 overflow vc v = 0 no overflow hi c = 1 and z = 0 higher, unsigned > ls c = 0 or z = 1 lower or same, unsigned ? ge n = v greater than or equal, signed ? lt n ? = v less than, signed < gt z = 0 and n = v greater than, signed > le z = 1 and n ?? v less than or equal, signed ? al can have any value always. this is the default when no suffix is specified.
93 sam4cp [datasheet] 43051e?atpl?08/14 to use an instruction width suffix, place it immediately after the instruction mnemonic and condition code, if any. the example below shows instructions with the instruction width suffix. bcs.w label ;creates a 32-bit instruction even for a short ;branch adds.w r0, r0, r1 ;creates a 32-bit instruction even though the same ;operation can be done by a 16-bit instruction 12.6.4 memory access instructions the table below shows the memory access instructions: 12.6.4.1 adr load pc-relative address. syntax adr{ cond } rd , label where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. label is a pc-relative expression. see ?pc-relative expressions? . operation adr determines the address by adding an immediate value to the pc, and writes the result to the destination register. adr produces position-independent code, because the address is pc-relative. if adr is used to generate a target address for a bx or blx instruction, ensure that bit[0] of the address generated is set to 1 for correct execution. values of label must be within the range of -4095 to +4095 from the address in the pc. note: the user might have to use the .w suffix to get the maximum offset range or to generate addresses that are not word-aligned. see ?instruction width selection? . table 12-17. memory access instructions mnemonic description adr load pc-relative address clrex clear exclusive ldm{mode} load multiple registers ldr{type} load register using immediate offset ldr{type} load register using register offset ldr{type}t load register with unprivileged access ldr load register using pc-relative address ldrd load register dual ldrex{type} load register exclusive pop pop registers from stack push push registers onto stack stm{mode} store multiple registers str{type} store register using immediate offset str{type} store register using register offset str{type}t store register with unprivileged access strex{type} store register exclusive
94 sam4cp [datasheet] 43051e?atpl?08/14 restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags. examples adr r1, textmessage ; write address value of a location labelled as ; textmessage to r1 12.6.4.2 ldr and str, immediate offset load and store with immediate offset, pre-indexed immediate offset, or post-indexed immediate offset. syntax op { type }{ cond } rt , [ rn {, # offset }] ; immediate offset op { type }{ cond } rt , [ rn , # offset ]! ; pre-indexed op { type }{ cond } rt , [ rn ], # offset ; post-indexed op d{ cond } rt , rt2 , [ rn {, # offset }] ; immediate offset, two words op d{ cond } rt , rt2 , [ rn , # offset ]! ; pre-indexed, two words op d{ cond } rt , rt2 , [ rn ], # offset ; post-indexed, two words where: op is one of: ldr load register. str store register. type is one of: b unsigned byte, zero extend to 32 bits on loads. sb signed byte, sign extend to 32 bits (ldr only). h unsigned halfword, zero extend to 32 bits on loads. sh signed halfword, sign extend to 32 bits (ldr only). - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rn is the register on which the memory address is based. offset is an offset from rn . if offset is omitted, the address is the contents of rn . rt2 is the additional register to load or store for two-word operations. operation ldr instructions load one or two registers with a value from memory. str instructions store one or two register values to memory. load and store instructions with immediate offset can use the following addressing modes: offset addressing the offset value is added to or subtracted from the address obtained from the register rn . the result is used as the address for the memory access. the register rn is unaltered. the assembly language syntax for this mode is: [ rn , # offset ] pre-indexed addressing the offset value is added to or subtracted from the address obtained from the register rn . the result is used as the address for the memory access and written back into the register rn . the assembly language syntax for this mode is: [ rn , # offset ]!
95 sam4cp [datasheet] 43051e?atpl?08/14 post-indexed addressing the address obtained from the register rn is used as the address for the memory access. the offset value is added to or subtracted from the address, and written back into the register rn . the assembly language syntax for this mode is: [ rn ], # offset the value to load or store can be a byte, halfword, word, or two words. bytes and halfwords can either be signed or unsigned. see ?address alignment? . the table below shows the ranges of offset for immediate, pre-indexed and post-indexed forms. restrictions for load instructions: ? rt can be sp or pc for word loads only. ? rt must be different from rt2 for two-word loads. ? rn must be different from rt and rt2 in the pre-indexed or post-indexed forms. when rt is pc in a word load instruction: ? bit[0] of the loaded value must be 1 for correct execution. ? a branch occurs to the address created by changing bit[0] of the loaded value to 0. ? if the instruction is conditional, it must be the last instruction in the it block. for store instructions: ? rt can be sp for word stores only. ? rt must not be pc. ? rn must not be pc. ? rn must be different from rt and rt2 in the pre-indexed or post-indexed forms. condition flags these instructions do not change the flags. examples ldr r8, [r10] ; loads r8 from the address in r10. ldrne r2, [r5, #960]! ; loads (conditionally) r2 from a word ; 960 bytes above the address in r5, and ; increments r5 by 960. str r2, [r9,#const-struc] ; const-struc is an expression evaluating ; to a constant in the range 0-4095. strh r3, [r4], #4 ; store r3 as halfword data into address in ; r4, then increment r4 by 4 ldrd r8, r9, [r3, #0x20] ; load r8 from a word 32 bytes above the ; address in r3, and load r9 from a word 36 ; bytes above the address in r3 strd r0, r1, [r8], #-16 ; store r0 to address in r8, and store r1 to ; a word 4 bytes above the address in r8, ; and then decrement r8 by 16. table 12-18. offset ranges instruction type immediate offset pre-indexed post-indexed word, halfword, signed halfword, byte, or signed byte -255 to 4095 -255 to 255 -255 to 255 two words multiple of 4 in the range -1020 to 1020 multiple of 4 in the range -1020 to 1020 multiple of 4 in the range -1020 to 1020
96 sam4cp [datasheet] 43051e?atpl?08/14 12.6.4.3 ldr and str, register offset load and store with register offset. syntax op { type }{ cond } rt , [ rn , rm {, lsl # n }] where: op is one of: ldr load register. str store register. type is one of: b unsigned byte, zero extend to 32 bits on loads. sb signed byte, sign extend to 32 bits (ldr only). h unsigned halfword, zero extend to 32 bits on loads. sh signed halfword, sign extend to 32 bits (ldr only). - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rn is the register on which the memory address is based. rm is a register containing a value to be used as the offset. lsl # n is an optional shift, with n in the range 0 to 3. operation ldr instructions load a register with a value from memory. str instructions store a register value into memory. the memory address to load from or store to is at an offset from the register rn . the offset is specified by the register rm and can be shifted left by up to 3 bits using lsl. the value to load or store can be a byte, halfword, or word. for load instructions, bytes and halfwords can either be signed or unsigned. see ?address alignment? . restrictions in these instructions: ? rn must not be pc. ? rm must not be sp and must not be pc. ? rt can be sp only for word loads and word stores. ? rt can be pc only for word loads. when rt is pc in a word load instruction: ? bit[0] of the loaded value must be 1 for correct execution, and a branch occurs to this halfword-aligned address. ? if the instruction is conditional, it must be the last instruction in the it block. condition flags these instructions do not change the flags. examples str r0, [r5, r1] ; store value of r0 into an address equal to ; sum of r5 and r1 ldrsb r0, [r5, r1, lsl #1] ; read byte value from an address equal to ; sum of r5 and two times r1, sign extended it ; to a word value and put it in r0 str r0, [r1, r2, lsl #2] ; stores r0 to an address equal to sum of r1 ; and four times r2
97 sam4cp [datasheet] 43051e?atpl?08/14 12.6.4.4 ldr and str, unprivileged load and store with unprivileged access. syntax op { type }t{ cond } rt , [ rn {, # offset }] ; immediate offset where: op is one of: ldr load register. str store register. type is one of: b unsigned byte, zero extend to 32 bits on loads. sb signed byte, sign extend to 32 bits (ldr only). h unsigned halfword, zero extend to 32 bits on loads. sh signed halfword, sign extend to 32 bits (ldr only). - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rn is the register on which the memory address is based. offset is an offset from rn and can be 0 to 255. if offset is omitted, the address is the value in rn . operation these load and store instructions perform the same function as the memory access instructions with immediate offset, see ?ldr and str, immediate offset? . the difference is that these instructions have only unprivileged access even when used in privileged software. when used in unprivileged software, these instructions behave in exactly the same way as normal memory access instructions with immediate offset. restrictions in these instructions: ? rn must not be pc. ? rt must not be sp and must not be pc. condition flags these instructions do not change the flags. examples strbteq r4, [r7] ; conditionally store least significant byte in ; r4 to an address in r7, with unprivileged access ldrht r2, [r2, #8] ; load halfword value from an address equal to ; sum of r2 and 8 into r2, with unprivileged access
98 sam4cp [datasheet] 43051e?atpl?08/14 12.6.4.5 ldr, pc-relative load register from memory. syntax ldr{ type }{ cond } rt , label ldrd{ cond } rt , rt2 , label ; load two words where: type is one of: b unsigned byte, zero extend to 32 bits. sb signed byte, sign extend to 32 bits. h unsigned halfword, zero extend to 32 bits. sh signed halfword, sign extend to 32 bits. - omit, for word. cond is an optional condition code, see ?conditional execution? . rt is the register to load or store. rt2 is the second register to load or store. label is a pc-relative expression. see ?pc-relative expressions? . operation ldr loads a register with a value from a pc-relative memory address. the memory address is specified by a label or by an offset from the pc. the value to load or store can be a byte, halfword, or word. for load instructions, bytes and halfwords can either be signed or unsigned. see ?address alignment? . label must be within a limited range of the current instruction. the table below shows the possible offsets between label and the pc. the user might have to use the .w suffix to get the maximum offset range. see ?instruction width selection? . restrictions in these instructions: ? rt can be sp or pc only for word loads. ? rt2 must not be sp and must not be pc. ? rt must be different from rt2. when rt is pc in a word load instruction: ? bit[0] of the loaded value must be 1 for correct execution, and a branch occurs to this halfword-aligned address. ? if the instruction is conditional, it must be the last instruction in the it block. condition flags these instructions do not change the flags. examples ldr r0, lookuptable ; load r0 with a word of data from an address ; labelled as lookuptable ldrsb r7, localdata ; load a byte value from an address labelled ; as localdata, sign extend it to a word ; value, and put it in r7 table 12-19. offset ranges instruction type offset range word, halfword, signed halfword, byte, signed byte -4095 to 4095 two words -1020 to 1020
99 sam4cp [datasheet] 43051e?atpl?08/14 12.6.4.6 ldm and stm load and store multiple registers. syntax op { addr_mode }{ cond } rn {!}, reglist where: op is one of: ldm load multiple registers. stm store multiple registers. addr_mode is any one of the following: ia increment address after each access. this is the default. db decrement address before each access. cond is an optional condition code, see ?conditional execution? . rn is the register on which the memory addresses are based. ! is an optional writeback suffix. if ! is present, the final address, that is loaded from or stored to, is written back into rn . reglist is a list of one or more registers to be loaded or stored, enclosed in braces. it can contain register ranges. it must be comma separated if it contains more than one register or register range, see ?examples? . ldm and ldmfd are synonyms for ldmia. ldmfd refers to its use for popping data from full descending stacks. ldmea is a synonym for ldmdb, and refers to its use for popping data from empty ascending stacks. stm and stmea are synonyms for stmia. stmea refers to its use for pushing data onto empty ascending stacks. stmfd is s synonym for stmdb, and refers to its use for pushing data onto full descending stacks. operation ldm instructions load the registers in reglist with word values from memory addresses based on rn . stm instructions store the word values in the registers in reglist to memory addresses based on rn . for ldm, ldmia, ldmfd, stm, stmia, and stmea the memory addresses used for the accesses are at 4-byte inter- vals ranging from rn to rn + 4 * ( n -1), where n is the number of registers in reglist . the accesses happens in order of increasing register numbers, with the lowest numbered register using the lowest memory address and the highest num- ber register using the highest memory address. if the writeback suffix is specified, the value of rn + 4 * ( n -1) is written back to rn . for ldmdb, ldmea, stmdb, and stmfd the memory addresses used for the accesses are at 4-byte intervals ranging from rn to rn - 4 * ( n -1), where n is the number of registers in reglist . the accesses happen in order of decreasing register numbers, with the highest numbered register using the highest memory address and the lowest number register using the lowest memory address. if the writeback suffix is specified, the value of rn - 4 * ( n -1) is written back to rn . the push and pop instructions can be expressed in this form. see ?push and pop? for details. restrictions in these instructions: ? rn must not be pc. ? reglist must not contain sp. ? in any stm instruction, reglist must not contain pc. ? in any ldm instruction, reglist must not contain pc if it contains lr. ? reglist must not contain rn if the writeback suffix is specified.
100 sam4cp [datasheet] 43051e?atpl?08/14 when pc is in reglist in an ldm instruction: ? bit[0] of the value loaded to the pc must be 1 for correct execution, and a branch occurs to this halfword-aligned address. ? if the instruction is conditional, it must be the last instruction in the it block. condition flags these instructions do not change the flags. examples ldm r8,{r0,r2,r9} ; ldmia is a synonym for ldm stmdb r1!,{r3-r6,r11,r12} incorrect examples stm r5!,{r5,r4,r9} ; value stored for r5 is unpredictable ldm r2, {} ; there must be at least one register in the list 12.6.4.7 push and pop push registers onto, and pop registers off a full-descending stack. syntax push{ cond } reglist pop{ cond } reglist where: cond is an optional condition code, see ?conditional execution? . reglist is a non-empty list of registers, enclosed in braces. it can contain register ranges. it must be comma separated if it contains more than one register or register range. push and pop are synonyms for stmdb and ldm (or ldmia) with the memory addresses for the access based on sp, and with the final address for the access written back to the sp. push and pop are the preferred mnemonics in these cases. operation push stores registers on the stack in order of decreasing the register numbers, with the highest numbered register using the highest memory address and the lowest numbered register using the lowest memory address. pop loads registers from the stack in order of increasing register numbers, with the lowest numbered register using the lowest memory address and the highest numbered register using the highest memory address. see ?ldm and stm? for more information. restrictions in these instructions: ? reglist must not contain sp. ? for the push instruction, reglist must not contain pc. ? for the pop instruction, reglist must not contain pc if it contains lr. when pc is in reglist in a pop instruction: ? bit[0] of the value loaded to the pc must be 1 for correct execution, and a branch occurs to this halfword-aligned address. ? if the instruction is conditional, it must be the last instruction in the it block. condition flags these instructions do not change the flags.
101 sam4cp [datasheet] 43051e?atpl?08/14 examples push {r0,r4-r7} push {r2,lr} pop {r0,r10,pc} 12.6.4.8 ldrex and strex load and store register exclusive. syntax ldrex{ cond } rt , [ rn {, # offset }] strex{ cond } rd , rt , [ rn {, # offset }] ldrexb{ cond } rt , [ rn ] strexb{ cond } rd , rt , [ rn ] ldrexh{ cond } rt , [ rn ] strexh{ cond } rd , rt , [ rn ] where: cond is an optional condition code, see ?conditional execution? . rd is the destination register for the returned status. rt is the register to load or store. rn is the register on which the memory address is based. offset is an optional offset applied to the value in rn . if offset is omitted, the address is the value in rn . operation ldrex, ldrexb, and ldrexh load a word, byte, and halfword respectively from a memory address. strex, strexb, and strexh attempt to store a word, byte, and halfword respectively to a memory address. the address used in any store-exclusive instruction must be th e same as the address in the most recently executed load- exclusive instruction. the value stored by the store-exclusive instruction must also have the same data size as the value loaded by the preceding load-exclusive instruction. this means software must always use a load-exclusive instruction and a matching store-exclusive instruction to perform a synchronization operation, see ?synchronization primitives? . if an store-exclusive instruction performs the store, it writes 0 to its destination register. if it does not perform the store , it writes 1 to its destination register. if th e store-exclusive instruction writes 0 to the destination register, it is guaranteed that no other process in the system has accessed the memory location between the load-exclusive and store-exclusive instructions. for reasons of performance, keep the number of instruct ions between corresponding load-exclusive and store-exclu- sive instruction to a minimum. the result of executing a store-exclusive instruction to an address that is different from that used in the preceding load- exclusive instruction is unpredictable. restrictions in these instructions: ? do not use pc. ? do not use sp for rd and rt. ? for strex, rd must be different from both rt and rn. ? the value of offset must be a multiple of four in the range 0-1020. condition flags these instructions do not change the flags.
102 sam4cp [datasheet] 43051e?atpl?08/14 examples mov r1, #0x1 ; initialize the ?lock taken? value try ldrex r0, [lockaddr] ; load the lock value cmp r0, #0 ; is the lock free? itt eq ; it instruction for strexeq and cmpeq strexeq r0, r1, [lockaddr] ; try and claim the lock cmpeq r0, #0 ; did this succeed? bne try ; no ? try again .... ; yes ? we have the lock 12.6.4.9 clrex clear exclusive. syntax clrex{ cond } where: cond is an optional condition code, see ?conditional execution? . operation use clrex to make the next strex, strexb, or strexh instruction write 1 to its destination register and fail to per- form the store. it is useful in exception handler code to force the failure of the store exclusive if the exception occurs between a load exclusive instruction and the matching store exclusive instruction in a synchronization operation. see ?synchronization primitives? for more information. condition flags these instructions do not change the flags. examples clrex
103 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5 general data processing instructions the table below shows the data processing instructions: table 12-20. data processing instructions mnemonic description adc add with carry add add addw add and logical and asr arithmetic shift right bic bit clear clz count leading zeros cmn compare negative cmp compare eor exclusive or lsl logical shift left lsr logical shift right mov move movt move top movw move 16-bit constant mvn move not orn logical or not orr logical or rbit reverse bits rev reverse byte order in a word rev16 reverse byte order in each halfword revsh reverse byte order in bottom halfword and sign extend ror rotate right rrx rotate right with extend rsb reverse subtract sadd16 signed add 16 sadd8 signed add 8 sasx signed add and subtract with exchange ssax signed subtract and add with exchange sbc subtract with carry shadd16 signed halving add 16 shadd8 signed halving add 8 shasx signed halving add and subtract with exchange shsax signed halving subtract and add with exchange shsub16 signed halving subtract 16
104 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.1 add, adc, sub, sbc, and rsb add, add with carry, subtract, subtract with carry, and reverse subtract. syntax op {s}{ cond } { rd ,} rn , operand2 op { cond } { rd ,} rn , # imm12 ; add and sub only where: op is one of: add add. adc add with carry. sub subtract. sbc subtract with carry. rsb reverse subtract. s is an optional suffix. if s is specified, the condition code flags are updated on the result of the operation, see ?conditional execution? . cond is an optional condition code, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . shsub8 signed halving subtract 8 ssub16 signed subtract 16 ssub8 signed subtract 8 sub subtract subw subtract teq test equivalence tst test uadd16 unsigned add 16 uadd8 unsigned add 8 uasx unsigned add and subtract with exchange usax unsigned subtract and add with exchange uhadd16 unsigned halving add 16 uhadd8 unsigned halving add 8 uhasx unsigned halving add and subtract with exchange uhsax unsigned halving subtract and add with exchange uhsub16 unsigned halving subtract 16 uhsub8 unsigned halving subtract 8 usad8 unsigned sum of absolute differences usada8 unsigned sum of absolute differences and accumulate usub16 unsigned subtract 16 usub8 unsigned subtract 8 table 12-20. data processing instructions (continued) mnemonic description
105 sam4cp [datasheet] 43051e?atpl?08/14 rn is the register holding the first operand. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. imm12 is any value in the range 0-4095. operation the add instruction adds the value of operand2 or imm12 to the value in rn . the adc instruction adds the values in rn and operand2 , together with the carry flag. the sub instruction subtracts the value of operand2 or imm12 from the value in rn . the sbc instruction subtracts the value of operand2 from the value in rn . if the carry flag is clear, the result is reduced by one. the rsb instruction subtracts the value in rn from the value of operand2 . this is useful because of the wide range of options for operand2 . use adc and sbc to synthesize multiword arithmetic, see multiword arithmetic examples on. see also ?adr? . note: addw is equivalent to the add syntax that uses the imm12 operand. subw is equivalent to the sub syntax that uses the imm12 operand. restrictions in these instructions: ? operand2 must not be sp and must not be pc. ? rd can be sp only in add and sub, and only with the additional restrictions: ? rn must also be sp. ? any shift in operand2 must be limited to a maximum of 3 bits using lsl. ? rn can be sp only in add and sub. ? rd can be pc only in the add{ cond } pc, pc, rm instruction where: ? the user must not specify the s suffix. ? rm must not be pc and must not be sp. ? if the instruction is conditional, it must be the last instruction in the it block. ? with the exception of the add{ cond } pc, pc, rm instruction, rn can be pc only in add and sub, and only with the additional restrictions: ? the user must not specify the s suffix. ? the second operand must be a constant in the range 0 to 4095. ? note: when using the pc for an addition or a subtraction, bits[1:0] of the pc are rounded to 0b00 before performing the calculation, making the base address for the calculation word-aligned. ? note: to generate the address of an instruction, the constant based on the value of the pc must be adjusted. arm recommends to use the adr instruction instead of add or sub with rn equal to the pc, because the assembler automatically calculates the correct constant for the adr instruction. when rd is pc in the add{ cond } pc, pc, rm instruction: ? bit[0] of the value written to the pc is ignored. ? a branch occurs to the address created by forcing bit[0] of that value to 0. condition flags if s is specified, these instructions update the n, z, c and v flags according to the result.
106 sam4cp [datasheet] 43051e?atpl?08/14 examples add r2, r1, r3 ; sets the flags on the result subs r8, r6, #240 ; subtracts contents of r4 from 1280 rsb r4, r4, #1280 ; only executed if c flag set and z adchi r11, r0, r3 ; flag clear. multiword arithmetic examples the example below shows two instructions that add a 64-bit integer contained in r2 and r3 to another 64-bit integer con- tained in r0 and r1, and place the result in r4 and r5. 64-bit addition example adds r4, r0, r2 ; add the least significant words adc r5, r1, r3 ; add the most significant words with carry multiword values do not have to use consecutive registers. the example below shows instructions that subtract a 96-bit integer contained in r9, r1, and r11 from another contained in r6, r2, and r8. the example stores the result in r6, r9, and r2. 96-bit subtraction example subs r6, r6, r9 ; subtract the least significant words sbcs r9, r2, r1 ; subtract the middle words with carry sbc r2, r8, r11 ; subtract the most significant words with carry 12.6.5.2 and, orr, eor, bic, and orn logical and, or, exclusive or, bit clear, and or not. syntax op {s}{ cond } { rd ,} rn , operand2 where: op is one of: and logical and. orr logical or, or bit set. eor logical exclusive or. bic logical and not, or bit clear. orn logical or not. s is an optional suffix. if s is specified, the condition code flags are updated on the result of the operation, see ?conditional execution? . cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the register holding the first operand. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. operation the and, eor, and orr instructions perform bitwise and, exclusive or, and or operations on the values in rn and operand2 . the bic instruction performs an and operation on the bits in rn with the complements of the corresponding bits in the value of operand2 . the orn instruction performs an or operation on the bits in rn with the complements of the corresponding bits in the value of operand2 . restrictions do not use sp and do not use pc.
107 sam4cp [datasheet] 43051e?atpl?08/14 condition flags if s is specified, these instructions: ? update the n and z flags according to the result. ? can update the c flag during the calculation of operand2 , see ?flexible second operand? . ? do not affect the v flag. examples and r9, r2, #0xff00 orreq r2, r0, r5 ands r9, r8, #0x19 eors r7, r11, #0x18181818 bic r0, r1, #0xab orn r7, r11, r14, ror #4 orns r7, r11, r14, asr #32 12.6.5.3 asr, lsl, lsr, ror, and rrx arithmetic shift right, logical shift left, logical shift right, rotate right, and rotate right with extend. syntax op {s}{ cond } rd , rm , rs op {s}{ cond } rd , rm , # n rrx{s}{ cond } rd , rm where: op is one of: asr arithmetic shift right. lsl logical shift left. lsr logical shift right. ror rotate right. s is an optional suffix. if s is specified, the condition code flags are updated on the result of the operation, see ?conditional execution? . rd is the destination register. rm is the register holding the value to be shifted. rs is the register holding the shift length to apply to the value in rm . only the least significant byte is used and can be in the range 0 to 255. n is the shift length. the range of shift length depends on the instruction: asr shift length from 1 to 32 lsl shift length from 0 to 31 lsr shift length from 1 to 32 ror shift length from 0 to 31 . movs rd, rm is the preferred syntax for lsls rd, rm, #0. operation asr, lsl, lsr, and ror move the bits in the register rm to the left or right by the number of places specified by constant n or register rs . rrx moves the bits in register rm to the right by 1. in all these instructions, the result is written to rd , but the value in register rm remains unchanged. for details on what result is generated by the different instructions, see ?shift operations? .
108 sam4cp [datasheet] 43051e?atpl?08/14 restrictions do not use sp and do not use pc. condition flags if s is specified: ? these instructions update the n and z flags according to the result. ? the c flag is updated to the last bit shifted out, except when the shift length is 0, see ?shift operations? . examples asr r7, r8, #9 ; arithmetic shift right by 9 bits sls r1, r2, #3 ; logical shift left by 3 bits with flag update lsr r4, r5, #6 ; logical shift right by 6 bits ror r4, r5, r6 ; rotate right by the value in the bottom byte of r6 rrx r4, r5 ; rotate right with extend. 12.6.5.4 clz count leading zeros. syntax clz{ cond } rd , rm where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm is the operand register. operation the clz instruction counts the number of leading zeros in the value in rm and returns the result in rd . the result value is 32 if no bits are set and zero if bit[31] is set. restrictions do not use sp and do not use pc. condition flags this instruction does not change the flags. examples clz r4,r9 clzne r2,r3 12.6.5.5 cmp and cmn compare and compare negative. syntax cmp{ cond } rn , operand2 cmn{ cond } rn , operand2 where: cond is an optional condition code, see ?conditional execution? . rn is the register holding the first operand. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. operation these instructions compare the value in a register with operand2 . they update the condition flags on the result, but do not write the result to a register.
109 sam4cp [datasheet] 43051e?atpl?08/14 the cmp instruction subtracts the value of operand2 from the value in rn . this is the same as a subs instruction, except that the result is discarded. the cmn instruction adds the value of operand2 to the value in rn . this is the same as an adds instruction, except that the result is discarded. restrictions in these instructions: ? do not use pc ? operand2 must not be sp. condition flags these instructions update the n, z, c and v flags according to the result. examples cmp r2, r9 cmn r0, #6400 cmpgt sp, r7, lsl #2 12.6.5.6 mov and mvn move and move not. syntax mov{s}{ cond } rd , operand2 mov{ cond } rd , # imm16 mvn{s}{ cond } rd , operand2 where: s is an optional suffix. if s is specified, the condition code flags are updated on the result of the operation, see ?conditional execution? . cond is an optional condition code, see ?conditional execution? . rd is the destination register. operand2 is a flexible second operand. see ?flexible second operand? for details of the options. imm16 is any value in the range 0-65535. operation the mov instruction copies the value of operand2 into rd . when operand2 in a mov instruction is a register with a shift other than lsl #0, the preferred syntax is the corresponding shift instruction: ? asr{s}{cond} rd, rm, #n is the preferred syntax for mov{s}{cond} rd, rm, asr #n. ? lsl{s}{cond} rd, rm, #n is the preferred syntax for mov{s}{cond} rd, rm, lsl #n if n != 0. ? lsr{s}{cond} rd, rm, #n is the preferred syntax for mov{s}{cond} rd, rm, lsr #n. ? ror{s}{cond} rd, rm, #n is the preferred syntax for mov{s}{cond} rd, rm, ror #n. ? rrx{s}{cond} rd, rm is the preferred syntax for mov{s}{cond} rd, rm, rrx. also, the mov instruction permits additional forms of operand2 as synonyms for shift instructions: ? mov{s}{cond} rd, rm, asr rs is a synonym for asr{s}{cond} rd, rm, rs. ? mov{s}{cond} rd, rm, lsl rs is a synonym for lsl{s}{cond} rd, rm, rs. ? mov{s}{cond} rd, rm, lsr rs is a synonym for lsr{s}{cond} rd, rm, rs. ? mov{s}{cond} rd, rm, ror rs is a synonym for ror{s}{cond} rd, rm, rs. see ?asr, lsl, lsr, ror, and rrx? . the mvn instruction takes the value of operand2 , performs a bitwise logical not operation on the value, and places the result into rd .
110 sam4cp [datasheet] 43051e?atpl?08/14 the movw instruction provides the same function as mov, but is restricted to using the imm16 operand. restrictions sp and pc only can be used in the mov instruction, with the following restrictions: ? the second operand must be a register without shift. ? the s suffix must not be specified. when rd is pc in a mov instruction: ? bit[0] of the value written to the pc is ignored. ? a branch occurs to the address created by forcing bit[0] of that value to 0. though it is possible to use mov as a branch instruction, arm strongly recommends the use of a bx or blx instruction to branch for software portability to the arm instruction set. condition flags if s is specified, these instructions: ? update the n and z flags according to the result. ? can update the c flag during the calculation of operand2 , see ?flexible second operand? . ? do not affect the v flag. examples movs r11, #0x000b ; write value of 0x000b to r11, flags get updated mov r1, #0xfa05 ; write value of 0xfa05 to r1, flags are not updated movs r10, r12 ; write value in r12 to r10, flags get updated mov r3, #23 ; write value of 23 to r3 mov r8, sp ; write value of stack pointer to r8 mvns r2, #0xf ; write value of 0xfffffff0 (bitwise inverse of 0xf) ; to the r2 and update flags. 12.6.5.7 movt move top. syntax movt{ cond } rd , # imm16 where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. imm16 is a 16-bit immediate constant. operation movt writes a 16-bit immediate value, imm16 , to the top halfword, rd [31:16], of its destination register. the write does not affect rd [15:0]. the mov, movt instruction pair enables to generate any 32-bit constant. restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags. examples movt r3, #0xf123 ; write 0xf123 to upper halfword of r3, lower halfword ; and apsr are unchanged.
111 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.8 rev, rev16, revsh, and rbit reverse bytes and reverse bits. syntax op { cond } rd , rn where: op is any of: rev reverse byte order in a word. rev16 reverse byte order in each halfword independently. revsh reverse byte order in the bottom halfword, and sign extend to 32 bits. rbit reverse the bit order in a 32-bit word. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the register holding the operand. operation use these instructions to change endianness of data: rev converts either: ? 32-bit big-endian data into little-endian data. ? 32-bit little-endian data into big-endian data. rev16 converts either: ? 16-bit big-endian data into little-endian data. ? 16-bit little-endian data into big-endian data. revsh converts either: ? 16-bit signed big-endian data into 32-bit signed little-endian data. ? 16-bit signed little-endian data into 32-bit signed big-endian data. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples rev r3, r7 ; reverse byte order of value in r7 and write it to r3 rev16 r0, r0 ; reverse byte order of each 16-bit halfword in r0 revsh r0, r5 ; reverse signed halfword revhs r3, r7 ; reverse with higher or same condition rbit r7, r8 ; reverse bit order of value in r8 and write the result to r7.
112 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.9 sadd16 and sadd8 signed add 16 and signed add 8 syntax op { cond }{ rd ,} rn , rm where: op is any of: sadd16 performs two 16-bit signed integer additions. sadd8 performs four 8-bit signed integer additions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first register holding the operand. rm is the second register holding the operand. operation use these instructions to perform a halfword or byte add in parallel: the sadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. writes the result in the corresponding halfwords of the destination register. the sadd8 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. writes the result in the corresponding bytes of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples sadd16 r1, r0 ;adds the halfwords in r0 to the corresponding ;halfwords of r1 and writes to corresponding halfword ;of r1. sadd8 r4, r0, r5 ;adds bytes of r0 to the corresponding byte in r5 and ;writes to the corresponding byte in r4. 12.6.5.10 shadd16 and shadd8 signed halving add 16 and signed halving add 8 syntax op { cond }{ rd ,} rn , rm where: op is any of: shadd16 signed halving add 16. shadd8 signed halving add 8. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register.
113 sam4cp [datasheet] 43051e?atpl?08/14 operation use these instructions to add 16-bit and 8-bit data and then to halve the result before writing the result to the destination register: the shadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. shuffles the result by one bit to the right, halving the data. 3. writes the halfword results in the destination register. the shaddb8 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. 2. shuffles the result by one bit to the right, halving the data. 3. writes the byte results in the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples shadd16 r1, r0 ;adds halfwords in r0 to corresponding halfword of r1 ;and writes halved result to corresponding halfword in ;r1 shadd8 r4, r0, r5 ;adds bytes of r0 to corresponding byte in r5 and ;writes halved result to corresponding byte in r4. 12.6.5.11 shasx and shsax signed halving add and subtract with exchange and signed halving subtract and add with exchange. syntax op{cond } { rd }, rn , rm where: op is any of: shasx add and subtract with exchange and halving. shsax subtract and add with exchange and halving. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the shasx instruction: 1. adds the top halfword of the first operand with the bottom halfword of the second operand. 2. writes the halfword result of the addition to the top halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving. 3. subtracts the top halfword of the second operand from the bottom highword of the first operand. 4. writes the halfword result of the division in the bottom halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving.
114 sam4cp [datasheet] 43051e?atpl?08/14 the shsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. writes the halfword result of the addition to the bottom halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving. 3. adds the bottom halfword of the first operand with the top halfword of the second operand. 4. writes the halfword result of the division in the top halfword of the destination register, shifted by one bit to the right causing a divide by two, or halving. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples shasx r7, r4, r2 ; adds top halfword of r4 to bottom halfword of r2 ; and writes halved result to top halfword of r7 ; subtracts top halfword of r2 from bottom halfword of ; r4 and writes halved result to bottom halfword of r7 shsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword ; of r3 and writes halved result to top halfword of r0 ; adds top halfword of r5 to bottom halfword of r3 and ; writes halved result to bottom halfword of r0. 12.6.5.12 shsub16 and shsub8 signed halving subtract 16 and signed halving subtract 8 syntax op { cond }{ rd ,} rn , rm where: op is any of: shsub16 signed halving subtract 16. shsub8 signed halving subtract 8. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation use these instructions to add 16-bit and 8-bit data and then to halve the result before writing the result to the destination register: the shsub16 instruction: 1. subtracts each halfword of the second operand from the corresponding halfwords of the first operand. 2. shuffles the result by one bit to the right, halving the data. 3. writes the halved halfword results in the destination register. the shsub8 instruction: 1. subtracts each byte of the second operand from the corresponding byte of the first operand. 2. shuffles the result by one bit to the right, halving the data. 3. writes the corresponding signed byte results in the destination register.
115 sam4cp [datasheet] 43051e?atpl?08/14 restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples shsub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword ; of r1 and writes to corresponding halfword of r1 shsub8 r4, r0, r5 ; subtracts bytes of r0 from corresponding byte in r5, ; and writes to corresponding byte in r4. 12.6.5.13 ssub16 and ssub8 signed subtract 16 and signed subtract 8 syntax op { cond }{ rd ,} rn , rm where: op is any of: ssub16 performs two 16-bit signed integer subtractions. ssub8 performs four 8-bit signed integer subtractions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation use these instructions to change endianness of data: the ssub16 instruction: 1. subtracts each halfword from the second operand from the corresponding halfword of the first operand. 2. writes the difference result of two signed halfwords in the corresponding halfword of the destination register. the ssub8 instruction: 1. subtracts each byte of the second operand from the corresponding byte of the first operand. 2. writes the difference result of four signed bytes in the corresponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples ssub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword ; of r1 and writes to corresponding halfword of r1 ssub8 r4, r0, r5 ; subtracts bytes of r5 from corresponding byte in ; r0, and writes to corresponding byte of r4.
116 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.14 sasx and ssax signed add and subtract with exchange and signed subtract and add with exchange. syntax op{cond } { rd }, rm , rn where: op is any of: sasx signed add and subtract with exchange. ssax signed subtract and add with exchange. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the sasx instruction: 1. adds the signed top halfword of the first operand with the signed bottom halfword of the second operand. 2. writes the signed result of the addition to the top halfword of the destination register. 3. subtracts the signed bottom halfword of the second operand from the top signed highword of the first operand. 4. writes the signed result of the subtraction to the bottom halfword of the destination register. the ssax instruction: 1. subtracts the signed bottom halfword of the second operand from the top signed highword of the first operand. 2. writes the signed result of the addition to the bottom halfword of the destination register. 3. adds the signed top halfword of the first operand with the signed bottom halfword of the second operand. 4. writes the signed result of the subtraction to the top halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples sasx r0, r4, r5 ; adds top halfword of r4 to bottom halfword of r5 and ; writes to top halfword of r0 ; subtracts bottom halfword of r5 from top halfword of r4 ; and writes to bottom halfword of r0 ssax r7, r3, r2 ; subtracts top halfword of r2 from bottom halfword of r3 ; and writes to bottom halfword of r7 ; adds top halfword of r3 with bottom halfword of r2 and ; writes to top halfword of r7. 12.6.5.15 tst and teq test bits and test equivalence. syntax tst{ cond } rn , operand2 teq{ cond } rn , operand2 where cond is an optional condition code, see ?conditional execution? . rn is the register holding the first operand.
117 sam4cp [datasheet] 43051e?atpl?08/14 operand2 is a flexible second operand. see ?flexible second operand? for details of the options. operation these instructions test the value in a register against operand2 . they update the condition flags based on the result, but do not write the result to a register. the tst instruction performs a bitwise and operation on the value in rn and the value of operand2 . this is the same as the ands instruction, except that it discards the result. to test whether a bit of rn is 0 or 1, use the tst instruction with an operand2 constant that has that bit set to 1 and all other bits cleared to 0. the teq instruction performs a bitwise exclusive or operation on the value in rn and the value of operand2 . this is the same as the eors instruction, except that it discards the result. use the teq instruction to test if two values are equal without affecting the v or c flags. teq is also useful for testing the sign of a value. after the comparison, the n flag is the logical exclusive or of the sign bits of the two operands. restrictions do not use sp and do not use pc . condition flags these instructions: ? update the n and z flags according to the result. ? can update the c flag during the calculation of operand2 , see ?flexible second operand? . ? do not affect the v flag. examples tst r0, #0x3f8 ; perform bitwise and of r0 value to 0x3f8, ; apsr is updated but result is discarded teqeq r10, r9 ; conditionally test if value in r10 is equal to ; value in r9, apsr is updated but result is discarded. 12.6.5.16 uadd16 and uadd8 unsigned add 16 and unsigned add 8 syntax op { cond }{ rd ,} rn , rm where: op is any of: uadd16 performs two 16-bit unsigned integer additions. uadd8 performs four 8-bit unsigned integer additions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first register holding the operand. rm is the second register holding the operand. operation use these instructions to add 16- and 8-bit unsigned data: the uadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. writes the unsigned result in the corresponding halfwords of the destination register.
118 sam4cp [datasheet] 43051e?atpl?08/14 the uadd8 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. 2. writes the unsigned result in the corresponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples uadd16 r1, r0 ; adds halfwords in r0 to corresponding halfword of r1, ; writes to corresponding halfword of r1 uadd8 r4, r0, r5 ; adds bytes of r0 to corresponding byte in r5 and ; writes to corresponding byte in r4. 12.6.5.17 uasx and usax add and subtract with exchange and subtract and add with exchange. syntax op{cond } { rd }, rn , rm where: op is one of: uasx add and subtract with exchange. usax subtract and add with exchange. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the uasx instruction: 1. subtracts the top halfword of the second operand from the bottom halfword of the first operand. 2. writes the unsigned result from the subtraction to the bottom halfword of the destination register. 3. adds the top halfword of the first operand with the bottom halfword of the second operand. 4. writes the unsigned result of the addition to the top halfword of the destination register. the usax instruction: 1. adds the bottom halfword of the first operand with the top halfword of the second operand. 2. writes the unsigned result of the addition to the bottom halfword of the destination register. 3. subtracts the bottom halfword of the second operand from the top halfword of the first operand. 4. writes the unsigned result from the subtraction to the top halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags.
119 sam4cp [datasheet] 43051e?atpl?08/14 examples uasx r0, r4, r5 ; adds top halfword of r4 to bottom halfword of r5 and ; writes to top halfword of r0 ; subtracts bottom halfword of r5 from top halfword of r0 ; and writes to bottom halfword of r0 usax r7, r3, r2 ; subtracts top halfword of r2 from bottom halfword of r3 ; and writes to bottom halfword of r7 ; adds top halfword of r3 to bottom halfword of r2 and ; writes to top halfword of r7. 12.6.5.18 uhadd16 and uhadd8 unsigned halving add 16 and unsigned halving add 8 syntax op { cond }{ rd ,} rn , rm where: op is any of: uhadd16 unsigned halving add 16. uhadd8 unsigned halving add 8. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the register holding the first operand. rm is the register holding the second operand. operation use these instructions to add 16- and 8-bi t data and then to halve the result before writing the result to the destination register: the uhadd16 instruction: 1. adds each halfword from the first operand to the corresponding halfword of the second operand. 2. shuffles the halfword result by one bit to the right, halving the data. 3. writes the unsigned results to the corresponding halfword in the destination register. the uhadd8 instruction: 1. adds each byte of the first operand to the corresponding byte of the second operand. 2. shuffles the byte result by one bit to the right, halving the data. 3. writes the unsigned results in the corresponding byte in the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples uhadd16 r7, r3 ; adds halfwords in r7 to corresponding halfword of r3 ; and writes halved result to corresponding halfword ; in r7 uhadd8 r4, r0, r5 ; adds bytes of r0 to corresponding byte in r5 and ; writes halved result to corresponding byte in r4.
120 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.19 uhasx and uhsax unsigned halving add and subtract with exchange and unsigned halving subtract and add with exchange. syntax op{cond } { rd }, rn , rm where: op is one of: uhasx add and subtract with exchange and halving. uhsax subtract and add with exchange and halving. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the uhasx instruction: 1. adds the top halfword of the first operand with the bottom halfword of the second operand. 2. shifts the result by one bit to the right causing a divide by two, or halving. 3. writes the halfword result of the addition to the top halfword of the destination register. 4. subtracts the top halfword of the second operand from the bottom highword of the first operand. 5. shifts the result by one bit to the right causing a divide by two, or halving. 6. writes the halfword result of the division in the bottom halfword of the destination register. the uhsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. shifts the result by one bit to the right causing a divide by two, or halving. 3. writes the halfword result of the subtraction in the top halfword of the destination register. 4. adds the bottom halfword of the first operand with the top halfword of the second operand. 5. shifts the result by one bit to the right causing a divide by two, or halving. 6. writes the halfword result of the addition to the bottom halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples uhasx r7, r4, r2 ; adds top halfword of r4 with bottom halfword of r2 ; and writes halved result to top halfword of r7 ; subtracts top halfword of r2 from bottom halfword of ; r7 and writes halved result to bottom halfword of r7 uhsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword of ; r3 and writes halved result to top halfword of r0 ; adds top halfword of r5 to bottom halfword of r3 and ; writes halved result to bottom halfword of r0.
121 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.20 uhsub16 and uhsub8 unsigned halving subtract 16 and unsigned halving subtract 8 syntax op { cond }{ rd ,} rn , rm where: op is any of: uhsub16 performs two unsigned 16-bit integer additions, halves the results, and writes the results to the destination register. uhsub8 performs four unsigned 8-bit integer additions, halves the results, and writes the results to the destination register. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first register holding the operand. rm is the second register holding the operand. operation use these instructions to add 16-bit and 8-bit data and then to halve the result before writing the result to the destination register: the uhsub16 instruction: 1. subtracts each halfword of the second operand from the corresponding halfword of the first operand. 2. shuffles each halfword result to the right by one bit, halving the data. 3. writes each unsigned halfword result to the corresponding halfwords in the destination register. the uhsub8 instruction: 1. subtracts each byte of second operand from the corresponding byte of the first operand. 2. shuffles each byte result by one bit to the right, halving the data. 3. writes the unsigned byte results to the corresponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples uhsub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword of ; r1 and writes halved result to corresponding halfword in r1 uhsub8 r4, r0, r5 ; subtracts bytes of r5 from corresponding byte in r0 and ; writes halved result to corresponding byte in r4.
122 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.21 sel select bytes. selects each byte of its result from either its first operand or its second operand, according to the values of the ge flags. syntax sel{}{} {,} , where: c, q are standard assembler syntax fields. rd is the destination register. rn is the first register holding the operand. rm is the second register holding the operand. operation the sel instruction: 1. reads the value of each bit of apsr.ge. 2. depending on the value of apsr.ge, assigns the destination register the value of either the first or second operand register. restrictions none. condition flags these instructions do not change the flags. examples sadd16 r0, r1, r2 ; set ge bits based on result sel r0, r0, r3 ; select bytes from r0 or r3, based on ge. 12.6.5.22 usad8 unsigned sum of absolute differences syntax usad8{ cond }{ rd ,} rn , rm where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation the usad8 instruction: 1. subtracts each byte of the second operand register from the corresponding byte of the first operand register. 2. adds the absolute values of the differences together. 3. writes the result to the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags.
123 sam4cp [datasheet] 43051e?atpl?08/14 examples usad8 r1, r4, r0 ; subtracts each byte in r0 from corresponding byte of r4 ; adds the differences and writes to r1 usad8 r0, r5 ; subtracts bytes of r5 from corresponding byte in r0 ; adds the differences and writes to r0. 12.6.5.23 usada8 unsigned sum of absolute differences and accumulate syntax usada8{ cond }{ rd ,} rn , rm , ra where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. ra is the register that contains the accumulation value. operation the usada8 instruction: 1. subtracts each byte of the second operand register from the corresponding byte of the first operand register. 2. adds the unsigned absolute differences together. 3. adds the accumulation value to the sum of the absolute differences. 4. writes the result to the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples usada8 r1, r0, r6 ; subtracts bytes in r0 from corresponding halfword of r1 ; adds differences, adds value of r6, writes to r1 usada8 r4, r0, r5, r2 ; subtracts bytes of r5 from corresponding byte in r0 ; adds differences, adds value of r2 writes to r4.
124 sam4cp [datasheet] 43051e?atpl?08/14 12.6.5.24 usub16 and usub8 unsigned subtract 16 and unsigned subtract 8 syntax op { cond }{ rd ,} rn , rm where op is any of: usub16 unsigned subtract 16. usub8 unsigned subtract 8. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register. operation use these instructions to subtract 16-bit and 8-bit data before writing the result to the destination register: the usub16 instruction: 1. subtracts each halfword from the second operand register from the corresponding halfword of the first operand register. 2. writes the unsigned result in the corresponding halfwords of the destination register. the usub8 instruction: 1. subtracts each byte of the second operand register from the corresponding byte of the first operand register. 2. writes the unsigned byte result in the corresponding byte of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples usub16 r1, r0 ; subtracts halfwords in r0 from corresponding halfword of r1 ; and writes to corresponding halfword in r1usub8 r4, r0, r5 ; subtracts bytes of r5 from corresponding byte in r0 and ; writes to the corresponding byte in r4.
125 sam4cp [datasheet] 43051e?atpl?08/14 12.6.6 multiply and divide instructions the table below shows the multiply and divide instructions: table 12-21. multiply and divide instructions mnemonic description mla multiply with accumulate, 32-bit result mls multiply and subtract, 32-bit result mul multiply, 32-bit result sdiv signed divide smla[b,t] signed multiply accumulate (halfwords) smlad , smladx signed multiply accumulate dual smlal signed multiply with accumulate (32x32+64), 64-bit result smlal[b,t] signed multiply accumulate long (halfwords) smlald , smlaldx signed multiply accumulate long dual smlaw[b|t] signed multiply accumulate (word by halfword) smlsd signed multiply subtract dual smlsld signed multiply subtract long dual smmla signed most significant word multiply accumulate smmls , smmlsr signed most significant word multiply subtract smuad, smuadx signed dual multiply add smul[b,t] signed multiply (word by halfword) smmul , smmulr signed most significant word multiply smull signed multiply (32x32), 64-bit result smulwb, smulwt signed multiply (word by halfword) smusd, smusdx signed dual multiply subtract udiv unsigned divide umaal unsigned multiply accumulate accumulate long (32x32+32+32), 64-bit result umlal unsigned multiply with accumulate (32x32+64), 64-bit result umull unsigned multiply (32x32), 64-bit result
126 sam4cp [datasheet] 43051e?atpl?08/14 12.6.6.1 mul, mla, and mls multiply, multiply with accumulate, and multiply with subtract, using 32-bit operands, and producing a 32-bit result. syntax mul{s}{ cond } { rd ,} rn , rm ; multiply mla{ cond } rd , rn , rm , ra ; multiply with accumulate mls{ cond } rd , rn , rm , ra ; multiply with subtract where: cond is an optional condition code, see ?conditional execution? . s is an optional suffix. if s is specified, the condition code flags are updated on the result of the operation, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . rn, rm are registers holding the values to be multiplied. ra is a register holding the value to be added or subtracted from. operation the mul instruction multiplies the values from rn and rm , and places the least significant 32 bits of the result in rd . the mla instruction multiplies the values from rn and rm , adds the value from ra , and places the least significant 32 bits of the result in rd . the mls instruction multiplies the values from rn and rm , subtracts the product from the value from ra , and places the least significant 32 bits of the result in rd . the results of these instructions do not depend on whether the operands are signed or unsigned. restrictions in these instructions, do not use sp and do not use pc. if the s suffix is used with the mul instruction: ? rd , rn , and rm must all be in the range r0 to r7. ? rd must be the same as rm. ? the cond suffix must not be used. condition flags if s is specified, the mul instruction: ? updates the n and z flags according to the result. ? does not affect the c and v flags. examples mul r10, r2, r5 ; multiply, r10 = r2 x r5 mla r10, r2, r1, r5 ; multiply with accumulate, r10 = (r2 x r1) + r5 muls r0, r2, r2 ; multiply with flag update, r0 = r2 x r2 mullt r2, r3, r2 ; conditionally multiply, r2 = r3 x r2 mls r4, r5, r6, r7 ; multiply with subtract, r4 = r7 - (r5 x r6)
127 sam4cp [datasheet] 43051e?atpl?08/14 12.6.6.2 umull, umaal, umlal unsigned long multiply, with optional accumulate, using 32-bit operands and producing a 64-bit result. syntax op { cond } rdlo , rdhi , rn , rm where: op is one of: umull unsigned long multiply. umaal unsigned long multiply with accumulate accumulate. umlal unsigned long multiply, with accumulate. cond is an optional condition code, see ?conditional execution? . rdhi, rdlo are the destination registers. for umaal, umlal and umlal they also hold the accumulating value. rn, rm are registers holding the first and second operands. operation these instructions interpret the values from rn and rm as unsigned 32-bit integers. the umull instruction: ? multiplies the two unsigned integers in the first and second operands. ? writes the least significant 32 bits of the result in rdlo. ? writes the most significant 32 bits of the result in rdhi . the umaal instruction: ? multiplies the two unsigned 32-bit integers in the first and second operands. ? adds the unsigned 32-bit integer in rdhi to the 64-bit result of the multiplication. ? adds the unsigned 32-bit integer in rdlo to the 64-bit result of the addition. ? writes the top 32-bits of the result to rdhi. ? writes the lower 32-bits of the result to rdlo . the umlal instruction: ? multiplies the two unsigned integers in the first and second operands. ? adds the 64-bit result to the 64-bit unsigned integer contained in rdhi and rdlo . ? writes the result back to rdhi and rdlo . restrictions in these instructions: ? do not use sp and do not use pc. ? rdhi and rdlo must be different registers. condition flags these instructions do not affect the condition code flags. examples umull r0, r4, r5, r6 ; multiplies r5 and r6, writes the top 32 bits to r4 ; and the bottom 32 bits to r0 umaal r3, r6, r2, r7 ; multiplies r2 and r7, adds r6, adds r3, writes the ; top 32 bits to r6, and the bottom 32 bits to r3 umlal r2, r1, r3, r5 ; multiplies r5 and r3, adds r1:r2, writes to r1:r2.
128 sam4cp [datasheet] 43051e?atpl?08/14 12.6.6.3 smla and smlaw signed multiply accumulate (halfwords). syntax op{ xy }{ cond } rd , rn , rm op{ y }{ cond } rd , rn , rm , ra where: op is one of: smla signed multiply accumulate long (halfwords). x and y specifies which half of the source registers rn and rm are used as the first and second multiply operand. if x is b , then the bottom halfword, bits [15:0], of rn is used. if x is t , then the top halfword, bits [31:16], of rn is used. if y is b , then the bottom halfword, bits [15:0], of rm is used. if y is t , then the top halfword, bits [31:16], of rm is used. smlaw signed multiply accumulate (word by halfword). y specifies which half of the source register rm is used as the second multiply operand. if y is t, then the top halfword, bits [31:16] of rm is used. if y is b, then the bottom halfword, bits [15:0] of rm is used. cond is an optional condition code, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . rn, rm are registers holding the values to be multiplied. ra is a register holding the value to be added or subtracted from. operation the smalbb, smlabt, smlatb, smlatt instructions: ? multiplies the specified signed halfword, top or bottom, values from rn and rm . ? adds the value in ra to the resulting 32-bit product. ? writes the result of the multiplication and addition in rd . the non-specified halfwords of the source registers are ignored. the smlawb and smlawt instructions: ? multiply the 32-bit signed values in rn with: ? the top signed halfword of rm , t instruction suffix. ? the bottom signed halfword of rm , b instruction suffix. ? add the 32-bit signed value in ra to the top 32 bits of the 48-bit product. ? writes the result of the multiplication and addition in rd . the bottom 16 bits of the 48-bit product are ignored. if overflow occurs during the addition of the accumulate valu e, the instruction sets the q flag in the apsr. no overflow can occur during the multiplication. restrictions in these instructions, do not use sp and do not use pc. condition flags if an overflow is detected, the q flag is set.
129 sam4cp [datasheet] 43051e?atpl?08/14 examples smlabb r5, r6, r4, r1 ; multiplies bottom halfwords of r6 and r4, adds ; r1 and writes to r5 smlatb r5, r6, r4, r1 ; multiplies top halfword of r6 with bottom halfword ; of r4, adds r1 and writes to r5 smlatt r5, r6, r4, r1 ; multiplies top halfwords of r6 and r4, adds ; r1 and writes the sum to r5 smlabt r5, r6, r4, r1 ; multiplies bottom halfword of r6 with top halfword ; of r4, adds r1 and writes to r5 smlabt r4, r3, r2 ; multiplies bottom halfword of r4 with top halfword of ; r3, adds r2 and writes to r4 smlawb r10, r2, r5, r3 ; multiplies r2 with bottom halfword of r5, adds ; r3 to the result and writes top 32-bits to r10 smlawt r10, r2, r1, r5 ; multiplies r2 with top halfword of r1, adds r5 ; and writes top 32-bits to r10. 12.6.6.4 smlad signed multiply accumulate long dual syntax op{ x }{ cond } rd , rn , rm , ra ; where: op is one of: smlad signed multiply accumulate dual. smladx signed multiply accumulate dual reverse. x specifies which halfword of the source register rn is used as the multiply operand. if x is omitted, the multiplications are bottom bottom and top top. if x is present, the multiplications are bottom top and top bottom. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register holding the values to be multiplied. rm the second operand register. ra is the accumulate value. operation the smlad and smladx instructions regard the two operands as four halfword 16-bit values. the smlad and smladx instructions: ? if x is not present, multiply the top signed halfword value in rn with the top signed halfword of rm and the bottom signed halfword values in rn with the bottom signed halfword of rm . ? or if x is present, multiply the top signed halfword value in rn with the bottom signed halfword of rm and the bottom signed halfword values in rn with the top signed halfword of rm . ? add both multiplication results to the signed 32-bit value in ra . ? writes the 32-bit signed result of the multiplication and addition to rd . restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags.
130 sam4cp [datasheet] 43051e?atpl?08/14 examples smlad r10, r2, r1, r5 ; multiplies two halfword values in r2 with ; corresponding halfwords in r1, adds r5 and ; writes to r10 smlaldx r0, r2, r4, r6 ; multiplies top halfword of r2 with bottom ; halfword of r4, multiplies bottom halfword of r2 ; with top halfword of r4, adds r6 and writes to ; r0. 12.6.6.5 smlal and smlald signed multiply accumulate long, signed multiply accumu late long (halfwords) and signed multiply accumulate long dual. syntax op { cond } rdlo , rdhi , rn , rm op {xy}{ cond } rdlo , rdhi , rn , rm op { x }{ cond } rdlo , rdhi , rn , rm where: op is one of: mlal signed multiply accumulate long. smlal signed multiply accumulate long (halfwords, x and y). x and y specify which halfword of the source registers rn and rm are used as the first and second multiply operand: if x is b, then the bottom halfword, bits [15:0], of rn is used. if x is t, then the top halfword, bits [31:16], of rn is used. if y is b, then the bottom halfword, bits [15:0], of rm is used. if y is t, then the top halfword, bits [31:16], of rm is used. smlald signed multiply accumulate long dual. smlaldx signed multiply accumulate long dual reversed. if the x is omitted, the multiplications are bottom bottom and top top. if x is present, the multiplications are bottom top and top bottom. cond is an optional condition code, see ?conditional execution? . rdhi, rdlo are the destination registers. rdlo is the lower 32 bits and rdhi is the upper 32 bits of the 64-bit integer. for smlal, smlalbb, smlalbt, smlaltb, smlaltt, smlald and smlaldx, they also hold the accumulating value. rn, rm are registers holding the first and second operands. operation the smlal instruction: ? multiplies the two?s complement signed word values from rn and rm . ? adds the 64-bit value in rdlo and rdhi to the resulting 64-bit product. ? writes the 64-bit result of the multiplication and addition in rdlo and rdhi . the smlalbb, smlalbt, smlaltb and smlaltt instructions: ? multiplies the specified signed halfword, top or bottom, values from rn and rm . ? adds the resulting sign-extended 32-bit product to the 64-bit value in rdlo and rdhi . ? writes the 64-bit result of the multiplication and addition in rdlo and rdhi . the non-specified halfwords of the source registers are ignored.
131 sam4cp [datasheet] 43051e?atpl?08/14 the smlald and smlaldx instructions interpret the values from rn and rm as four halfword two?s complement signed 16-bit integers. these instructions: ? if x is not present, multiply the top signed halfword value of rn with the top signed halfword of rm and the bottom signed halfword values of rn with the bottom signed halfword of rm . ? or if x is present, multiply the top signed halfword value of rn with the bottom signed halfword of rm and the bottom signed halfword values of rn with the top signed halfword of rm . ? add the two multiplication results to the signed 64-bit value in rdlo and rdhi to create the resulting 64-bit product. ? write the 64-bit product in rdlo and rdhi . restrictions in these instructions: ? do not use sp and do not use pc. ? rdhi and rdlo must be different registers. condition flags these instructions do not affect the condition code flags. examples smlal r4, r5, r3, r8 ; multiplies r3 and r8, adds r5:r4 and writes to ; r5:r4 smlalbt r2, r1, r6, r7 ; multiplies bottom halfword of r6 with top ; halfword of r7, sign extends to 32-bit, adds ; r1:r2 and writes to r1:r2 smlaltb r2, r1, r6, r7 ; multiplies top halfword of r6 with bottom ; halfword of r7,sign extends to 32-bit, adds r1:r2 ; and writes to r1:r2 smlald r6, r8, r5, r1 ; multiplies top halfwords in r5 and r1 and bottom ; halfwords of r5 and r1, adds r8:r6 and writes to ; r8:r6 smlaldx r6, r8, r5, r1 ; multiplies top halfword in r5 with bottom ; halfword of r1, and bottom halfword of r5 with ; top halfword of r1, adds r8:r6 and writes to ; r8:r6. 12.6.6.6 smlsd and smlsld signed multiply subtract dual and signed multiply subtract long dual syntax op { x }{ cond } rd , rn , rm , ra where: op is one of: smlsd signed multiply subtract dual. smlsdx signed multiply subtract dual reversed. smlsld signed multiply subtract long dual. smlsldx signed multiply subtract long dual reversed. smlaw signed multiply accumulate (word by halfword). if x is present, the multiplications are bottom top and top bottom. if the x is omitted, the multiplications are bottom bottom and top top. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. ra is the register holding the accumulate value.
132 sam4cp [datasheet] 43051e?atpl?08/14 operation the smlsd instruction interprets the values from the first and second operands as four signed halfwords. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-bit halfword multiplications. ? subtracts the result of the upper halfword multiplication from the result of the lower halfword multiplication. ? adds the signed accumulate value to the result of the subtraction. ? writes the result of the addition to the destination register. the smlsld instruction interprets the values from rn and rm as four signed halfwords. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-bit halfword multiplications. ? subtracts the result of the upper halfword multiplication from the result of the lower halfword multiplication. ? adds the 64-bit value in rdhi and rdlo to the result of the subtraction. ? writes the 64-bit result of the addition to the rdhi and rdlo . restrictions in these instructions: ? do not use sp and do not use pc. condition flags this instruction sets the q flag if the accumulate operation overflows. overflow cannot occur during the multiplications or subtraction. for the thumb instruction set, these instructions do not affect the condition code flags. examples smlsd r0, r4, r5, r6 ; multiplies bottom halfword of r4 with bottom ; halfword of r5, multiplies top halfword of r4 ; with top halfword of r5, subtracts second from ; first, adds r6, writes to r0 smlsdx r1, r3, r2, r0 ; multiplies bottom halfword of r3 with top ; halfword of r2, multiplies top halfword of r3 ; with bottom halfword of r2, subtracts second from ; first, adds r0, writes to r1 smlsld r3, r6, r2, r7 ; multiplies bottom halfword of r6 with bottom ; halfword of r2, multiplies top halfword of r6 ; with top halfword of r2, subtracts second from ; first, adds r6:r3, writes to r6:r3 smlsldx r3, r6, r2, r7 ; multiplies bottom halfword of r6 with top ; halfword of r2, multiplies top halfword of r6 ; with bottom halfword of r2, subtracts second from ; first, adds r6:r3, writes to r6:r3.
133 sam4cp [datasheet] 43051e?atpl?08/14 12.6.6.7 smmla and smmls signed most significant word multiply accumulate and signed most significant word multiply subtract syntax op{ r }{ cond } rd , rn , rm , ra where: op is one of: smmla signed most significant word multiply accumulate. smmls signed most significant word multiply subtract. if the x is omitted, the multiplications are bottom bottom and top top. r is a rounding error flag. if r is specified, the result is rounded instead of being truncated. in this case the constant 0x80000000 is added to the product before the high word is extracted. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second multiply operands. ra is the register holding the accumulate value. operation the smmla instruction interprets the values from rn and rm as signed 32-bit words. the smmla instruction: ? multiplies the values in rn and rm . ? optionally rounds the result by adding 0x80000000. ? extracts the most significant 32 bits of the result. ? adds the value of ra to the signed extracted value. ? writes the result of the addition in rd . the smmls instruction interprets the values from rn and rm as signed 32-bit words. the smmls instruction: ? multiplies the values in rn and rm . ? optionally rounds the result by adding 0x80000000. ? extracts the most significant 32 bits of the result. ? subtracts the extracted value of the result from the value in ra . ? writes the result of the subtraction in rd . restrictions in these instructions: ? do not use sp and do not use pc. condition flags these instructions do not affect the condition code flags. examples smmla r0, r4, r5, r6 ; multiplies r4 and r5, extracts top 32 bits, adds ; r6, truncates and writes to r0 smmlar r6, r2, r1, r4 ; multiplies r2 and r1, extracts top 32 bits, adds ; r4, rounds and writes to r6 smmlsr r3, r6, r2, r7 ; multiplies r6 and r2, extracts top 32 bits, ; subtracts r7, rounds and writes to r3 smmls r4, r5, r3, r8 ; multiplies r5 and r3, extracts top 32 bits, ; subtracts r8, truncates and writes to r4.
134 sam4cp [datasheet] 43051e?atpl?08/14 12.6.6.8 smmul signed most significant word multiply syntax op{ r }{ cond } rd , rn , rm where: op is one of: smmul signed most significant word multiply. r is a rounding error flag. if r is specified, the result is rounded instead of being truncated. in this case the constant 0x80000000 is added to the product before the high word is extracted. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the smmul instruction interprets the values from rn and rm as two?s complement 32-bit signed integers. the smmul instruction: ? multiplies the values from rn and rm . ? optionally rounds the result, otherwise truncates the result. ? writes the most significant signed 32 bits of the result in rd . restrictions in this instruction: ? do not use sp and do not use pc. condition flags this instruction does not affect the condition code flags. examples smull r0, r4, r5 ; multiplies r4 and r5, truncates top 32 bits ; and writes to r0 smullr r6, r2 ; multiplies r6 and r2, rounds the top 32 bits ; and writes to r6. 12.6.6.9 smuad and smusd signed dual multiply add and signed dual multiply subtract syntax op {x}{ cond } rd , rn , rm where: op is one of: smuad signed dual multiply add. smuadx signed dual multiply add reversed. smusd signed dual multiply subtract. smusdx signed dual multiply subtract reversed. if x is present, the multiplications are bottom top and top bottom. if the x is omitted, the multiplications are bottom bottom and top top. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands.
135 sam4cp [datasheet] 43051e?atpl?08/14 operation the smuad instruction interprets the values from the first and second operands as two signed halfwords in each operand. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-bit multiplications. ? adds the two multiplication results together. ? writes the result of the addition to the destination register. the smusd instruction interprets the values from the fi rst and second operands as two?s complement signed integers. this instruction: ? optionally rotates the halfwords of the second operand. ? performs two signed 16 16-bit multiplications. ? subtracts the result of the top halfword multiplication from the result of the bottom halfword multiplication. ? writes the result of the subtraction to the destination register. restrictions in these instructions: ? do not use sp and do not use pc. condition flags sets the q flag if the addition overflows. the multiplications cannot overflow. examples smuad r0, r4, r5 ; multiplies bottom halfword of r4 with the bottom ; halfword of r5, adds multiplication of top halfword ; of r4 with top halfword of r5, writes to r0 smuadx r3, r7, r4 ; multiplies bottom halfword of r7 with top halfword ; of r4, adds multiplication of top halfword of r7 ; with bottom halfword of r4, writes to r3 smusd r3, r6, r2 ; multiplies bottom halfword of r4 with bottom halfword ; of r6, subtracts multiplication of top halfword of r6 ; with top halfword of r3, writes to r3 smusdx r4, r5, r3 ; multiplies bottom halfword of r5 with top halfword of ; r3, subtracts multiplication of top halfword of r5 ; with bottom halfword of r3, writes to r4. 12.6.6.10 smul and smulw signed multiply (halfwords) and signed multiply (word by halfword). syntax op { xy }{ cond } rd , rn , rm op { y }{ cond } rd . rn , rm for smulxy only: op is one of: smul{ xy } signed multiply (halfwords). x and y specify which halfword of the source registers rn and rm is used as the first and second multiply operand. if x is b, then the bottom halfword, bits [15:0] of rn is used. if x is t, then the top halfword, bits [31:16] of rn is used.if y is b, then the bottom halfword, bits [15:0], of rm is used. if y is t, then the top halfword, bits [31:16], of rm is used. smulw{y} signed multiply (word by halfword).
136 sam4cp [datasheet] 43051e?atpl?08/14 y specifies which halfword of the source register rm is used as the second multiply operand. if y is b, then the bottom halfword (bits [15:0]) of rm is used. if y is t, then the top halfword (bits [31:16]) of rm is used. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the smulbb, smultb, smulbt and smultt instructions interprets the values from rn and rm as four signed 16-bit integers. these instructions: ? multiplies the specified signed halfword, top or bottom, values from rn and rm . ? writes the 32-bit result of the multiplication in rd. the smulwt and smulwb instructions interprets the values from rn as a 32-bit signed integer and rm as two halfword 16-bit signed integers. these instructions: ? multiplies the first operand and the top, t suffix, or the bottom, b suffix, halfword of the second operand. ? writes the signed most significant 32 bits of the 48-bit result in the destination register. restrictions in these instructions: ? do not use sp and do not use pc. ? rdhi and rdlo must be different registers. examples smulbt r0, r4, r5 ; multiplies the bottom halfword of r4 with the ; top halfword of r5, multiplies results and ; writes to r0 smulbb r0, r4, r5 ; multiplies the bottom halfword of r4 with the ; bottom halfword of r5, multiplies results and ; writes to r0 smultt r0, r4, r5 ; multiplies the top halfword of r4 with the top ; halfword of r5, multiplies results and writes ; to r0 smultb r0, r4, r5 ; multiplies the top halfword of r4 with the ; bottom halfword of r5, multiplies results and ; and writes to r0 smulwt r4, r5, r3 ; multiplies r5 with the top halfword of r3, ; extracts top 32 bits and writes to r4 smulwb r4, r5, r3 ; multiplies r5 with the bottom halfword of r3, ; extracts top 32 bits and writes to r4. 12.6.6.11 umull, umlal, smull, and smlal signed and unsigned long multiply, with optional accumulate, using 32-bit operands and producing a 64-bit result. syntax op { cond } rdlo , rdhi , rn , rm where: op is one of: umull unsigned long multiply. umlal unsigned long multiply, with accumulate. smull signed long multiply. smlal signed long multiply, with accumulate.
137 sam4cp [datasheet] 43051e?atpl?08/14 cond is an optional condition code, see ?conditional execution? . rdhi, rdlo are the destination registers. for umlal and smlal they also hold the accumulating value. rn, rm are registers holding the operands. operation the umull instruction interprets the values from rn and rm as unsigned integers. it multiplies these integers and places the least significant 32 bits of the result in rdlo , and the most significant 32 bits of the result in rdhi . the umlal instruction interprets the values from rn and rm as unsigned integers. it multiplies these integers, adds the 64-bit result to the 64-bit unsigned integer contained in rdhi and rdlo , and writes the result back to rdhi and rdlo . the smull instruction interprets the values from rn and rm as two?s complement signed integers. it multiplies these integers and places the least significant 32 bits of the result in rdlo , and the most significant 32 bits of the result in rdhi . the smlal instruction int erprets the values from rn and rm as two?s complement signed integers. it multiplies these integers, adds the 64-bit result to the 64-bit signed integer contained in rdhi and rdlo , and writes the result back to rdhi and rdlo . restrictions in these instructions: ? do not use sp and do not use pc. ? rdhi and rdlo must be different registers. condition flags these instructions do not affect the condition code flags. examples umull r0, r4, r5, r6 ; unsigned (r4,r0) = r5 x r6 smlal r4, r5, r3, r8 ; signed (r5,r4) = (r5,r4) + r3 x r8 12.6.6.12 sdiv and udiv signed divide and unsigned divide. syntax sdiv{ cond } { rd ,} rn , rm udiv{ cond } { rd ,} rn, rm where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. if rd is omitted, the destination register is rn . rn is the register holding the value to be divided. rm is a register holding the divisor. operation sdiv performs a signed integer division of the value in rn by the value in rm . udiv performs an unsigned integer division of the value in rn by the value in rm . for both instructions, if the value in rn is not divisible by the value in rm , the result is rounded towards zero. restrictions do not use sp and do not use pc . condition flags these instructions do not change the flags. examples sdiv r0, r2, r4 ; signed divide, r0 = r2/r4 udiv r8, r8, r1 ; unsigned divide, r8 = r8/r1
138 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7 saturating instructions the table below shows the saturating instructions: for signed n -bit saturation, this means that: ? if the value to be saturated is less than -2 n - 1 , the result returned is -2 n-1 . ? if the value to be saturated is greater than 2 n - 1 -1, the result returned is 2 n-1 -1. ? otherwise, the result returned is the same as the value to be saturated. for unsigned n -bit saturation, this means that: ? if the value to be saturated is less than 0, the result returned is 0. ? if the value to be saturated is greater than 2 n -1, the result returned is 2 n -1. ? otherwise, the result returned is the same as the value to be saturated. if the returned result is different from the value to be saturated, it is called saturation . if saturation occurs, the instruction sets the q flag to 1 in the apsr. otherwise, it leaves the q flag unchanged. to clear the q flag to 0, the msr instruction must be used; see ?msr? . to read the state of the q flag, the mrs instruction must be used; see ?mrs? . table 12-22. saturating instructions mnemonic description ssat signed saturate ssat16 signed saturate halfword usat unsigned saturate usat16 unsigned saturate halfword qadd saturating add qsub saturating subtract qsub16 saturating subtract 16 qasx saturating add and subtract with exchange qsax saturating subtract and add with exchange qdadd saturating double and add qdsub saturating double and subtract uqadd16 unsigned saturating add 16 uqadd8 unsigned saturating add 8 uqasx unsigned saturating add and subtract with exchange uqsax unsigned saturating subtract and add with exchange uqsub16 unsigned saturating subtract 16 uqsub8 unsigned saturating subtract 8
139 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7.1 ssat and usat signed saturate and unsigned saturate to any bit position, with optional shift before saturating. syntax op { cond } rd , # n , rm {, shift #s} where: op is one of: ssat saturates a signed value to a signed range. usat saturates a signed value to an unsigned range. cond is an optional condition code, see ?conditional execution? . rd is the destination register. n specifies the bit position to saturate to: n ranges from 1 n ranges from 0 to 31 for usat. to 32 for ssat rm is the register containing the value to saturate. shift #s is an optional shift applied to rm before saturating. it must be one of the following: asr #s where s is in the range 1 to 31. lsl #s where s is in the range 0 to 31. operation these instructions saturate to a signed or unsigned n -bit value. the ssat instruction applies the specified shift, then saturates to the signed range -2 n ?1 x 2 n ?1 -1. the usat instruction applies the specified shift, then saturates to the unsigned range 0 x 2 n -1. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. if saturation occurs, these instructions set the q flag to 1. examples ssat r7, #16, r7, lsl #4 ; logical shift left value in r7 by 4, then ; saturate it as a signed 16-bit value and ; write it back to r7 usatne r0, #7, r5 ; conditionally saturate value in r5 as an ; unsigned 7 bit value and write it to r0.
140 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7.2 ssat16 and usat16 signed saturate and unsigned saturate to any bit position for two halfwords. syntax op { cond } rd , # n , rm where: op is one of: ssat16 saturates a signed halfword value to a signed range. usat16 saturates a signed halfword value to an unsigned range. cond is an optional condition code, see ?conditional execution? . rd is the destination register. n specifies the bit position to saturate to: n ranges from 1 n ranges from 0 to 15 for usat. to 16 for ssat rm is the register containing the value to saturate. operation the ssat16 instruction: saturates two signed 16-bit halfword values of the register with the value to saturate from selected by the bit position in n . writes the results as two signed 16-bit halfwords to the destination register. the usat16 instruction: saturates two unsigned 16-bit halfword values of the register with the value to saturate from selected by the bit position in n . writes the results as two unsigned halfwords in the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. if saturation occurs, these instructions set the q flag to 1. examples ssat16 r7, #9, r2 ; saturates the top and bottom highwords of r2 ; as 9-bit values, writes to corresponding halfword ; of r7 usat16ne r0, #13, r5 ; conditionally saturates the top and bottom ; halfwords of r5 as 13-bit values, writes to ; corresponding halfword of r0.
141 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7.3 qadd and qsub saturating add and saturating subtract, signed. syntax op{ cond } { rd }, rn , rm op{ cond } { rd }, rn , rm where: op is one of: qadd saturating 32-bit add. qadd8 saturating four 8-bit integer additions. qadd16 saturating two 16-bit integer additions. qsub saturating 32-bit subtraction. qsub8 saturating four 8-bit integer subtraction. qsub16 saturating two 16-bit integer subtraction. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation these instructions add or subtract two, four or eight values from the first and second operands and then writes a signed saturated value in the destination register. the qadd and qsub instructions apply the specified add or subtract, and then saturate the result to the signed range -2 n ?1 ? x ? 2 n ?1 -1, where x is given by the number of bits applied in the instruction, 32, 16 or 8. if the returned result is different from the value to be saturated, it is called saturation . if saturation occurs, the qadd and qsub instructions set the q flag to 1 in the apsr. otherwise, it leaves the q flag unchanged. the 8-bit and 16-bit qadd and qsub instructions always leave the q flag unchanged. to clear the q flag to 0, the msr instruction must be used; see ?msr? . to read the state of the q flag, the mrs instruction must be used; see ?mrs? . restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. if saturation occurs, these instructions set the q flag to 1. examples qadd16 r7, r4, r2 ; adds halfwords of r4 with corresponding halfword of ; r2, saturates to 16 bits and writes to ; corresponding halfword of r7 qadd8 r3, r1, r6 ; adds bytes of r1 to the corresponding bytes of r6, ; saturates to 8 bits and writes to corresponding ; byte of r3 qsub16 r4, r2, r3 ; subtracts halfwords of r3 from corresponding ; halfword of r2, saturates to 16 bits, writes to ; corresponding halfword of r4 qsub8 r4, r2, r5 ; subtracts bytes of r5 from the corresponding byte ; in r2, saturates to 8 bits, writes to corresponding ; byte of r4.
142 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7.4 qasx and qsax saturating add and subtract with exchange and saturating subtract and add with exchange, signed. syntax op{cond } { rd }, rm , rn where: op is one of: qasx add and subtract with exchange and saturate. qsax subtract and add with exchange and saturate. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the qasx instruction: 1. adds the top halfword of the source operand with the bottom halfword of the second operand. 2. subtracts the top halfword of the second operand from the bottom highword of the first operand. 3. saturates the result of the subtraction and writes a 16-bit signed integer in the range ?2 15 ? x ? 2 15 ? 1, where x equals 16, to the bottom halfword of the destination register. 4. saturates the results of the sum and writes a 16-bit signed integer in the range ?2 15 ? x ? 2 15 ? 1, where x equals 16, to the top halfword of the destination register. the qsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. adds the bottom halfword of the source operand with the top halfword of the second operand. 3. saturates the results of the sum and writes a 16-bit signed integer in the range ?2 15 ? x ? 2 15 ? 1, where x equals 16, to the bottom halfword of the destination register. 4. saturates the result of the subtraction and writes a 16-bit signed integer in the range ?2 15 ? x ? 2 15 ? 1, where x equals 16, to the top halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples qasx r7, r4, r2 ; adds top halfword of r4 to bottom halfword of r2, ; saturates to 16 bits, writes to top halfword of r7 ; subtracts top highword of r2 from bottom halfword of ; r4, saturates to 16 bits and writes to bottom halfword ; of r7 qsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword of ; r3, saturates to 16 bits, writes to top halfword of r0 ; adds bottom halfword of r3 to top halfword of r5, ; saturates to 16 bits, writes to bottom halfword of r0.
143 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7.5 qdadd and qdsub saturating double and add and saturating double and subtract, signed. syntax op { cond } { rd }, rm , rn where: op is one of: qdadd saturating double and add. qdsub saturating double and subtract. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm, rn are registers holding the first and second operands. operation the qdadd instruction: ? doubles the second operand value. ? adds the result of the doubling to the signed saturated value in the first operand. ? writes the result to the destination register. the qdsub instruction: ? doubles the second operand value. ? subtracts the doubled value from the signed saturated value in the first operand. ? writes the result to the destination register. both the doubling and the addition or subtraction have their results saturated to the 32-bit signed integer range ?2 31 ? x ? 2 31 ? 1. if saturation occurs in either operation, it sets the q flag in the apsr. restrictions do not use sp and do not use pc . condition flags if saturation occurs, these instructions set the q flag to 1. examples qdadd r7, r4, r2 ; doubles and saturates r4 to 32 bits, adds r2, ; saturates to 32 bits, writes to r7 qdsub r0, r3, r5 ; subtracts r3 doubled and saturated to 32 bits ; from r5, saturates to 32 bits, writes to r0.
144 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7.6 uqasx and uqsax saturating add and subtract with exchange and saturating subtract and add with exchange, unsigned. syntax op{cond } { rd }, rm , rn where: type is one of: uqasx add and subtract with exchange and saturate. uqsax subtract and add with exchange and saturate. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation the uqasx instruction: 1. adds the bottom halfword of the source operand with the top halfword of the second operand. 2. subtracts the bottom halfword of the second operand from the top highword of the first operand. 3. saturates the results of the sum and writes a 16-bit unsigned integer in the range 0 ? x ? 2 16 ? 1, where x equals 16, to the top halfword of the destination register. 4. saturates the result of the subtraction and writes a 16-bit unsigned integer in the range 0 ? x ? 2 16 ? 1, where x equals 16, to the bottom halfword of the destination register. the uqsax instruction: 1. subtracts the bottom halfword of the second operand from the top highword of the first operand. 2. adds the bottom halfword of the first operand with the top halfword of the second operand. 3. saturates the result of the subtraction and writes a 16-bit unsigned integer in the range 0 ? x ? 2 16 ? 1, where x equals 16, to the top halfword of the destination register. 4. saturates the results of the addition and writes a 16-bit unsigned integer in the range 0 ? x ? 2 16 ? 1, where x equals 16, to the bottom halfword of the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples uqasx r7, r4, r2 ; adds top halfword of r4 with bottom halfword of r2, ; saturates to 16 bits, writes to top halfword of r7 ; subtracts top halfword of r2 from bottom halfword of ; r4, saturates to 16 bits, writes to bottom halfword of r7 uqsax r0, r3, r5 ; subtracts bottom halfword of r5 from top halfword of r3, ; saturates to 16 bits, writes to top halfword of r0 ; adds bottom halfword of r4 to top halfword of r5 ; saturates to 16 bits, writes to bottom halfword of r0.
145 sam4cp [datasheet] 43051e?atpl?08/14 12.6.7.7 uqadd and uqsub saturating add and saturating subtract unsigned. syntax op { cond } { rd }, rn , rm op { cond } { rd }, rn , rm where: op is one of: uqadd8 saturating four unsigned 8-bit integer additions. uqadd16 saturating two unsigned 16-bit integer additions. udsub8 saturating four unsigned 8-bit integer subtractions. uqsub16 saturating two unsigned 16-bit integer subtractions. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn, rm are registers holding the first and second operands. operation these instructions add or subtract two or four values and then writes an unsigned saturated value in the destination register. the uqadd16 instruction: ? adds the respective top and bottom halfwords of the first and second operands. ? saturates the result of the additions for each halfword in the destination register to the unsigned range 0 ?? x ? 2 16 -1, where x is 16. the uqadd8 instruction: ? adds each respective byte of the first and second operands. ? saturates the result of the addition for each byte in the destination register to the unsigned range 0 ? x ? 2 8 -1, where x is 8. the uqsub16 instruction: ? subtracts both halfwords of the second operand from the respective halfwords of the first operand. ? saturates the result of the differences in the destination register to the unsigned range 0 ? x ? 2 16 -1, where x is 16. the uqsub8 instructions: ? subtracts the respective bytes of the second operand from the respective bytes of the first operand. ? saturates the results of the differences for each byte in the destination register to the unsigned range 0 ? x ? 2 8 -1, where x is 8. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the condition code flags. examples uqadd16 r7,r4,r2 ; adds halfwords in r4 to corresponding halfword in r2, ; saturates to 16 bits, writes to corresponding halfword of r7 uqadd8 r4,r2,r5 ; adds bytes of r2 to corresponding byte of r5, saturates ; to 8 bits, writes to corresponding bytes of r4 uqsub16 r6,r3,r0 ; subtracts halfwords in r0 from corresponding halfword ; in r3, saturates to 16 bits, writes to corresponding ; halfword in r6 uqsub8 r1,r5,r6 ; subtracts bytes in r6 from corresponding byte of r5, ; saturates to 8 bits, writes to corresponding byte of r1.
146 sam4cp [datasheet] 43051e?atpl?08/14 12.6.8 packing and unpacking instructions the table below shows the instructions that operate on packing and unpacking data: table 12-23. packing and unpacking instructions mnemonic description pkh pack halfword sxtab extend 8 bits to 32 and add sxtab16 dual extend 8 bits to 16 and add sxtah extend 16 bits to 32 and add sxtb sign extend a byte sxtb16 dual extend 8 bits to 16 and add sxth sign extend a halfword uxtab extend 8 bits to 32 and add uxtab16 dual extend 8 bits to 16 and add uxtah extend 16 bits to 32 and add uxtb zero extend a byte uxtb16 dual zero extend 8 bits to 16 and add uxth zero extend a halfword
147 sam4cp [datasheet] 43051e?atpl?08/14 12.6.8.1 pkhbt and pkhtb pack halfword syntax op{ cond } { rd }, rn , rm {, lsl # imm } op{ cond } { rd }, rn , rm {, asr # imm } where: op is one of: pkhbt pack halfword, bottom and top with shift. pkhtb pack halfword, top and bottom with shift. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the second operand register holding the value to be optionally shifted. imm is the shift length. the type of shift length depends on the instruction: for pkhbt lsl a left shift with a shift length from 1 to 31, 0 means no shift. for pkhtb asr an arithmetic shift right with a shift length from 1 to 32, a shift of 32-bits is encoded as 0b00000. operation the pkhbt instruction: 1. writes the value of the bottom halfword of the first operand to the bottom halfword of the destination register. 2. if shifted, the shifted value of the second operand is written to the top halfword of the destination register. the pkhtb instruction: 1. writes the value of the top halfword of the first operand to the top halfword of the destination register. 2. if shifted, the shifted value of the second operand is written to the bottom halfword of the destination register. restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags. examples pkhbt r3, r4, r5 lsl #0 ; writes bottom halfword of r4 to bottom halfword of ; r3, writes top halfword of r5, unshifted, to top ; halfword of r3 pkhtb r4, r0, r2 asr #1 ; writes r2 shifted right by 1 bit to bottom halfword ; of r4, and writes top halfword of r0 to top ; halfword of r4.
148 sam4cp [datasheet] 43051e?atpl?08/14 12.6.8.2 sxt and uxt sign extend and zero extend. syntax op{ cond } { rd ,} rm {, ror # n } op{ cond } { rd }, rm {, ror # n } where: op is one of: sxtb sign extends an 8-bit value to a 32-bit value. sxth sign extends a 16-bit value to a 32-bit value. sxtb16 sign extends two 8-bit values to two 16-bit values. uxtb zero extends an 8-bit value to a 32-bit value. uxth zero extends a 16-bit value to a 32-bit value. uxtb16 zero extends two 8-bit values to two 16-bit values. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm is the register holding the value to extend. ror #n is one of: ror #8 value from rm is rotated right 8 bits. operation these instructions do the following: 1. rotate the value from rm right by 0, 8, 16 or 24 bits. 2. extract bits from the resulting value: ? sxtb extracts bits[7:0] and sign extends to 32 bits. ? uxtb extracts bits[7:0] and zero extends to 32 bits. ? sxth extracts bits[15:0] and sign extends to 32 bits. ? uxth extracts bits[15:0] and zero extends to 32 bits. ? sxtb16 extracts bits[7:0] and sign extends to 16 bits, and extracts bits [23:16] and sign extends to 16 bits. ? uxtb16 extracts bits[7:0] and zero extends to 16 bits, and extracts bits [23:16] and zero extends to 16 bits. restrictions do not use sp and do not use pc. condition flags these instructions do not affect the flags. examples sxth r4, r6, ror #16 ; rotates r6 right by 16 bits, obtains bottom halfword of ; of result, sign extends to 32 bits and writes to r4 uxtb r3, r10 ; extracts lowest byte of value in r10, zero extends, and ; writes to r3.
149 sam4cp [datasheet] 43051e?atpl?08/14 12.6.8.3 sxta and uxta signed and unsigned extend and add syntax op { cond } { rd ,} rn , rm {, ror # n } op { cond } { rd ,} rn , rm {, ror # n } where: op is one of: sxtab sign extends an 8-bit value to a 32-bit value and add. sxtah sign extends a 16-bit value to a 32-bit value and add. sxtab16 sign extends two 8-bit values to two 16-bit values and add. uxtab zero extends an 8-bit value to a 32-bit value and add. uxtah zero extends a 16-bit value to a 32-bit value and add. uxtab16 zero extends two 8-bit values to two 16-bit values and add. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the first operand register. rm is the register holding the value to rotate and extend. ror #n is one of: ror #8 value from rm is rotated right 8 bits. ror #16 value from rm is rotated right 16 bits. ror #24 value from rm is rotated right 24 bits. if ror # n is omitted, no rotation is performed. operation these instructions do the following: 1. rotate the value from rm right by 0, 8, 16 or 24 bits. 2. extract bits from the resulting value: ? sxtab extracts bits[7:0] from rm and sign extends to 32 bits. ? uxtab extracts bits[7:0] from rm and zero extends to 32 bits. ? sxtah extracts bits[15:0] from rm and sign extends to 32 bits. ? uxtah extracts bits[15:0] from rm and zero extends to 32 bits. ? sxtab16 extracts bits[7:0] from rm and sign extends to 16 bits, and extracts bits [23:16] from rm and sign extends to 16 bits. ? uxtab16 extracts bits[7:0] from rm and zero extends to 16 bits, and extracts bits [23:16] from rm and zero extends to 16 bits. 3. adds the signed or zero extended value to the word or corresponding halfword of rn and writes the result in rd . restrictions do not use sp and do not use pc. condition flags these instructions do not affect the flags. examples sxtah r4, r8, r6, ror #16 ; rotates r6 right by 16 bits, obtains bottom ; halfword, sign extends to 32 bits, adds ; r8,and writes to r4 uxtab r3, r4, r10 ; extracts bottom byte of r10 and zero extends ; to 32 bits, adds r4, and writes to r3.
150 sam4cp [datasheet] 43051e?atpl?08/14 12.6.9 bitfield instructions the table below shows the instructions that operate on adjacent sets of bits in registers or bitfields: 12.6.9.1 bfc and bfi bit field clear and bit field insert. syntax bfc{ cond } rd , # lsb , # width bfi{ cond } rd , rn , # lsb , # width where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the source register. lsb is the position of the least significant bit of the bitfield. lsb must be in the range 0 to 31. width is the width of the bitfield and must be in the range 1 to 32- lsb . operation bfc clears a bitfield in a register. it clears width bits in rd , starting at the low bit position lsb . other bits in rd are unchanged. bfi copies a bitfield into one register from another register. it replaces width bits in rd starting at the low bit position lsb , with width bits from rn starting at bit[0]. other bits in rd are unchanged. restrictions do not use sp and do not use pc. condition flags these instructions do not affect the flags. examples bfc r4, #8, #12 ; clear bit 8 to bit 19 (12 bits) of r4 to 0 bfi r9, r2, #8, #12 ; replace bit 8 to bit 19 (12 bits) of r9 with ; bit 0 to bit 11 from r2. table 12-24. packing and unpacking instructions mnemonic description bfc bit field clear bfi bit field insert sbfx signed bit field extract sxtb sign extend a byte sxth sign extend a halfword ubfx unsigned bit field extract uxtb zero extend a byte uxth zero extend a halfword
151 sam4cp [datasheet] 43051e?atpl?08/14 12.6.9.2 sbfx and ubfx signed bit field extract and unsigned bit field extract. syntax sbfx{ cond } rd , rn , # lsb , # width ubfx{ cond } rd , rn , # lsb , # width where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. rn is the source register. lsb is the position of the least significant bit of the bitfield. lsb must be in the range 0 to 31. width is the width of the bitfield and must be in the range 1 to 32- lsb . operation sbfx extracts a bitfield from one register, sign extends it to 32 bits, and writes the result to the destination register. ubfx extracts a bitfield from one register, zero extends it to 32 bits, and writes the result to the destination register. restrictions do not use sp and do not use pc . condition flags these instructions do not affect the flags. examples sbfx r0, r1, #20, #4 ; extract bit 20 to bit 23 (4 bits) from r1 and sign ; extend to 32 bits and then write the result to r0. ubfx r8, r11, #9, #10 ; extract bit 9 to bit 18 (10 bits) from r11 and zero ; extend to 32 bits and then write the result to r8. 12.6.9.3 sxt and uxt sign extend and zero extend. syntax sxt extend { cond } { rd ,} rm {, ror # n } uxt extend { cond } { rd }, rm {, ror # n } where: extend is one of: b extends an 8-bit value to a 32-bit value. h extends a 16-bit value to a 32-bit value. cond is an optional condition code, see ?conditional execution? . rd is the destination register. rm is the register holding the value to extend. ror #n is one of: ror #8 value from rm is rotated right 8 bits. ror #16 value from rm is rotated right 16 bits. ror #24 value from rm is rotated right 24 bits. if ror # n is omitted, no rotation is performed.
152 sam4cp [datasheet] 43051e?atpl?08/14 operation these instructions do the following: 1. rotate the value from rm right by 0, 8, 16 or 24 bits. 2. extract bits from the resulting value: ? sxtb extracts bits[7:0] and sign extends to 32 bits. ? uxtb extracts bits[7:0] and zero extends to 32 bits. ? sxth extracts bits[15:0] and sign extends to 32 bits. ? uxth extracts bits[15:0] and zero extends to 32 bits. restrictions do not use sp and do not use pc. condition flags these instructions do not affect the flags. examples sxth r4, r6, ror #16 ; rotate r6 right by 16 bits, then obtain the lower ; halfword of the result and then sign extend to ; 32 bits and write the result to r4. uxtb r3, r10 ; extract lowest byte of the value in r10 and zero ; extend it, and write the result to r3. 12.6.10 branch and control instructions the table below shows the branch and control instructions: table 12-25. branch and control instructions mnemonic description b branch bl branch with link blx branch indirect with link bx branch indirect cbnz compare and branch if non zero cbz compare and branch if zero it if-then tbb table branch byte tbh table branch halfword
153 sam4cp [datasheet] 43051e?atpl?08/14 12.6.10.1 b, bl, bx, and blx branch instructions. syntax b{ cond } label bl{ cond } label bx{ cond } rm blx{ cond } rm where: b is branch (immediate). bl is branch with link (immediate). bx is branch indirect (register). blx is branch indirect with link (register). cond is an optional condition code, see ?conditional execution? . label is a pc-relative expression. see ?pc-relative expressions? . rm is a register that indicates an address to branch to. bit[0] of the value in rm must be 1, but the address to branch to is created by changing bit[0] to 0. operation all these instructions cause a branch to label , or to the address indicated in rm . in addition: ? the bl and blx instructions write the address of the next instruction to lr (the link register, r14). ? the bx and blx instructions result in a usagefault exception if bit[0] of rm is 0. b cond label is the only conditional instruction that can be either inside or outside an it block. all other branch instructions must be conditional inside an it block, and must be unconditional outside the it block, see ?it? . the table below shows the ranges for the various branch instructions. the .w suffix might be used to get the maximum branch range. see ?instruction width selection? . restrictions the restrictions are: ? do not use pc in the blx instruction. ? for bx and blx, bit[0] of rm must be 1 for correct execution but a branch occurs to the target address created by changing bit[0] to 0. ? when any of these instructions is inside an it block, it must be the last instruction of the it block. b cond is the only conditional instruction that is not required to be inside an it block. however, it has a longer branch range when it is inside an it block. condition flags these instructions do not change the flags. table 12-26. branch ranges instruction branch range b label -16 mb to +16 mb bcond label (outside it block) -1 mb to +1 mb bcond label (inside it block) -16 mb to +16 mb bl{ cond } label -16 mb to +16 mb bx{ cond } rm any value in register blx{ cond } rm any value in register
154 sam4cp [datasheet] 43051e?atpl?08/14 examples b loopa ; branch to loopa ble ng ; conditionally branch to label ng b.w target ; branch to target within 16mb range beq target ; conditionally branch to target beq.w target ; conditionally branch to target within 1mb bl func ; branch with link (call) to function func, return address ; stored in lr bx lr ; return from function call bxne r0 ; conditionally branch to address stored in r0 blx r0 ; branch with link and exchange (call) to a address stored in r0 12.6.10.2 cbz and cbnz compare and branch on zero, compare and branch on non-zero. syntax cbz rn , label cbnz rn , label where: rn is the register holding the operand. label is the branch destination. operation use the cbz or cbnz instructions to avoid changing the condition code flags and to reduce the number of instructions. cbz rn, label does not change condition flags but is otherwise equivalent to: cmp rn, #0 beq label cbnz rn, label does not change condition flags but is otherwise equivalent to: cmp rn, #0 bne label restrictions the restrictions are: ? rn must be in the range of r0 to r7. ? the branch destination must be within 4 to 130 bytes after the instruction. ? these instructions must not be used inside an it block. condition flags these instructions do not change the flags. examples cbz r5, target ; forward branch if r5 is zero cbnz r0, target ; forward branch if r0 is not zero
155 sam4cp [datasheet] 43051e?atpl?08/14 12.6.10.3 it if-then condition instruction. syntax it{ x { y { z }}} cond where: x specifies the condition switch for the second instruction in the it block. y specifies the condition switch for the third instruction in the it block. z specifies the condition switch for the fourth instruction in the it block. cond specifies the condition for the first instruction in the it block. the condition switch for the second, third and fourth instruction in the it block can be either: t then. applies the condition cond to the instruction. e else. applies the inverse condition of cond to the instruction. it is possible to use al (the always condition) for cond in an it instruction. if this is done, all of the instructions in the it block must be unconditional, and each of x , y , and z must be t or omitted but not e. operation the it instruction makes up to four following instructions conditional. the conditions can be all the same, or some of them can be the logical inverse of the others. the conditional instructions following the it instruction form the it block . the instructions in the it block, including any branches, must specify the condition in the { cond } part of their syntax. the assembler might be able to generate the required it instructions for conditional instructions automatically, so that the user does not have to write them. see the assembler documentation for details. a bkpt instruction in an it block is always executed, even if its condition fails. exceptions can be taken between an it instruction and the corresponding it block, or within an it block. such an exception results in entry to the appropriate exception handler, with suitable return information in lr and stacked psr. instructions designed for use for exception returns can be used as normal to return from the exception, and execution of the it block resumes correctly. this is the only way that a pc-modifying instruction is permitted to branch to an instruction in an it block. restrictions the following instructions are not permitted in an it block: ? it. ? cbz and cbnz. ? cpsid and cpsie. other restrictions when using an it block are: ? a branch or any instruction that modifies the pc must either be outside an it block or must be the last instruction inside the it block. these are: ? add pc, pc, rm. ? mov pc, rm. ? b, bl, bx, blx. ? any ldm, ldr, or pop instruction that writes to the pc. ? tbb and tbh. ? do not branch to any instruction inside an it block, except when returning from an exception handler. ? all conditional instructions except b cond must be inside an it block. b cond can be either outside or inside an it block but has a larger branch range if it is inside one. ? each instruction inside the it block must specify a condition code suffix that is either the same or logical inverse as for the other instructions in the block.
156 sam4cp [datasheet] 43051e?atpl?08/14 your assembler might place extra restrictions on the use of it blocks, such as prohibiting the use of assembler directives within them. condition flags this instruction does not change the flags. example itte ne ; next 3 instructions are conditional andne r0, r0, r1 ; andne does not update condition flags addsne r2, r2, #1 ; addsne updates condition flags moveq r2, r3 ; conditional move cmp r0, #9 ; convert r0 hex value (0 to 15) into ascii ; ('0'-'9', 'a'-'f') ite gt ; next 2 instructions are conditional addgt r1, r0, #55 ; convert 0xa -> 'a' addle r1, r0, #48 ; convert 0x0 -> '0' it gt ; it block with only one conditional instruction addgt r1, r1, #1 ; increment r1 conditionally ittee eq ; next 4 instructions are conditional moveq r0, r1 ; conditional move addeq r2, r2, #10 ; conditional add andne r3, r3, #1 ; conditional and bne.w dloop ; branch instruction can only be used in the last ; instruction of an it block it ne ; next instruction is conditional add r0, r0, r1 ; syntax error: no condition code used in it block 12.6.10.4 tbb and tbh table branch byte and table branch halfword. syntax tbb [ rn , rm ] tbh [ rn , rm , lsl #1] where: rn is the register containing the address of the table of branch lengths. if rn is pc, then the address of the table is the address of the byte immediately following the tbb or tbh instruction. rm is the index register. this contains an index into the table. for halfword tables, lsl #1 doubles the value in rm to form the right offset into the table. operation these instructions cause a pc-relative forward branch using a table of single byte offsets for tbb, or halfword offsets for tbh. rn provides a pointer to the table, and rm supplies an index into the table. for tbb the branch offset is twice the unsigned value of the byte returned from the table. and for tbh the branch offset is twice the unsigned value of the half- word returned from the table. the branch occurs to the addres s at that offset from the address of the byte immediately after the tbb or tbh instruction.
157 sam4cp [datasheet] 43051e?atpl?08/14 restrictions the restrictions are: ? rn must not be sp. ? rm must not be sp and must not be pc. ? when any of these instructions is used inside an it block, it must be the last instruction of the it block. condition flags these instructions do not change the flags. examples adr.w r0, branchtable_byte tbb [r0, r1] ; r1 is the index, r0 is the base address of the ; branch table case1 ; an instruction sequence follows case2 ; an instruction sequence follows case3 ; an instruction sequence follows branchtable_byte dcb 0 ; case1 offset calculation dcb ((case2-case1)/2) ; case2 offset calculation dcb ((case3-case1)/2) ; case3 offset calculation tbh [pc, r1, lsl #1] ; r1 is the index, pc is used as base of the ; branch table branchtable_h dci ((casea - branchtable_h)/2) ; casea offset calculation dci ((caseb - branchtable_h)/2) ; caseb offset calculation dci ((casec - branchtable_h)/2) ; casec offset calculation casea ; an instruction sequence follows caseb ; an instruction sequence follows casec ; an instruction sequence follows
158 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11 floating-point instructions the table below shows the floating-point instructions. these instructions are only available if the fpu is included, and enabled, in the system. see ?enabling the fpu? for information about enabling the floating-point unit. table 12-27. floating-point instructions mnemonic description vabs floating-point absolute vadd floating-point add vcmp compare two floating-point registers, or one floating-point register and zero vcmpe compare two floating-point registers, or one floating-point register and zero with invalid operation check vcvt convert between floating-point and integer vcvt convert between floating-point and fixed point vcvtr convert between floating-point and integer with rounding vcvtb converts half-precision value to single-precision vcvtt converts single-precision register to half-precision vdiv floating-point divide vfma floating-point fused multiply accumulate vfnma floating-point fused negate multiply accumulate vfms floating-point fused multiply subtract vfnms floating-point fused negate multiply subtract vldm load multiple extension registers vldr loads an extension register from memory vlma floating-point multiply accumulate vlms floating-point multiply subtract vmov floating-point move immediate vmov floating-point move register vmov copy arm core register to single precision vmov copy 2 arm core registers to 2 single precision vmov copies between arm core register to scalar vmov copies between scalar to arm core register vmrs move to arm core register from floating-point system register vmsr move to floating-point system register from arm core register vmul multiply floating-point vneg floating-point negate vnmla floating-point multiply and add vnmls floating-point multiply and subtract vnmul floating-point multiply vpop pop extension registers vpush push extension registers vsqrt floating-point square root vstm store multiple extension registers vstr stores an extension register to memory vsub floating-point subtract
159 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11.1 vabs floating-point absolute. syntax vabs{ cond }.f32 sd , sm where: cond is an optional condition code, see ?conditional execution? . sd, sm are the destination floating-point value and the operand floating-point value. operation this instruction: 1. takes the absolute value of the operand floating-point register. 2. places the results in the destination floating-point register. restrictions there are no restrictions. condition flags the floating-point instruction clears the sign bit. examples vabs.f32 s4, s6 12.6.11.2 vadd floating-point add syntax vadd{ cond }.f32 { sd ,} sn , sm where: cond is an optional condition code, see ?conditional execution? . sd, is the destination floating-point value. sn, sm are the operand floating-point values. operation this instruction: 1. adds the values in the two floating-point operand registers. 2. places the results in the destination floating-point register. restrictions there are no restrictions. condition flags this instruction does not change the flags. examples vadd.f32 s4, s6, s7 12.6.11.3 vcmp, vcmpe compares two floating-point registers, or one floating-point register and zero. syntax vcmp{ e }{ cond }.f32 sd , sm vcmp{ e }{ cond }.f32 sd , #0.0 where: cond is an optional condition code, see ?conditional execution? .
160 sam4cp [datasheet] 43051e?atpl?08/14 e if present, any nan operand causes an invalid operation exception. otherwise, only a signaling nan causes the exception. sd is the floating-point operand to compare. sm is the floating-point operand that is compared with. operation this instruction: 1. compares: ? two floating-point registers. ? one floating-point register and zero. 2. writes the result to the fpscr flags. restrictions this instruction can optionally raise an invalid operation exception if either operand is any type of nan. it always raises an invalid operation exception if either operand is a signaling nan. condition flags when this instruction writes the result to the fpscr flags, the values are normally transferred to the arm flags by a sub- sequent vmrs instruction. examples vcmp.f32 s4, #0.0 vcmp.f32 s4, s2 12.6.11.4 vcvt, vcvtr between floating-point and integer converts a value in a register from floating-point to a 32-bit integer. syntax vcvt{ r }{ cond }. tm .f32 sd , sm vcvt{ cond }.f32. tm sd , sm where: r if r is specified, the operation uses the rounding mode specified by the fpscr. if r is omitted. the operation uses the round towards zero rounding mode. cond is an optional condition code, see ?conditional execution? . tm is the data type for the operand. it must be one of: s32 signed 32- u32 unsigned 32-bit value. sd, sm are the destination register and the operand register. operation these instructions: 1. either ? converts a value in a register from floating-point value to a 32-bit integer. ? converts from a 32-bit integer to floating-point value. 2. places the result in a second register. the floating-point to integer operation normally uses the round towards zero rounding mode, but can optionally use the rounding mode specified by the fpscr. the integer to floating-point operation uses the rounding mode specified by the fpscr. restrictions there are no restrictions. condition flags these instructions do not change the flags.
161 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11.5 vcvt between floating-point and fixed-point converts a value in a register from floating-point to and from fixed-point. syntax vcvt{ cond }. td .f32 sd , sd , # fbits vcvt{ cond }.f32. td sd , sd , # fbits where: cond is an optional condition code, see ?conditional execution? . td is the data type for the fixed-point number. it must be one of: s16 signed 16-bit value. u16 unsigned 16-bit value. s32 signed 32-bit value. u32 unsigned 32-bit value. sd is the destination register and the operand register. fbits is the number of fraction bits in the fixed-point number: if td is s16 or u16, fbits must be in the range 0-16. if td is s32 or u32, fbits must be in the range 1-32. operation these instructions: 1. either ? converts a value in a register from floating-point to fixed-point. ? converts a value in a register from fixed-point to floating-point. 2. places the result in a second register. the floating-point values are single-precision. the fixed-point value can be 16-bit or 32-bit. conversions from fixed-point values take their operand from the low-order bits of the source register and ignore any remaining bits. signed conversions to fixed-point values sign-extend the result value to the destination register width. unsigned conversions to fixed-point values zero-extend the result value to the destination register width. the floating-point to fixed-point operation uses the round towards zero rounding mode. the fixed-point to floating-point operation uses the round to nearest rounding mode. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.6 vcvtb, vcvtt converts between a half-precision value and a single-precision value. syntax vcvt{ y }{ cond }.f32.f16 sd , sm vcvt{ y }{ cond }.f16.f32 sd , sm where: y specifies which half of the operand register sm or destination register sd is used for the operand or destination: - if y is b, then the bottom half, bits [15:0], of sm or sd is used. - if y is t, then the top half, bits [31:16], of sm or sd is used. cond is an optional condition code, see ?conditional execution? .
162 sam4cp [datasheet] 43051e?atpl?08/14 sd is the destination register. sm is the operand register. operation this instruction with the .f16.32 suffix: 1. converts the half-precision value in the top or bottom half of a single-precision. register to single-precision. 2. writes the result to a single-precision register. this instruction with the .f32.f16 suffix: 1. converts the value in a single-precision register to half-precision. 2. writes the result into the top or bottom half of a single-precision register, preserving the other half of the target register. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.7 vdiv divides floating-point values. syntax vdiv{ cond }.f32 { sd ,} sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination register. sn, sm are the operand registers. operation this instruction: 1. divides one floating-point value by another floating-point value. 2. writes the result to the floating-point destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.8 vfma, vfms floating-point fused multiply accumulate and subtract. syntax vfma{ cond }.f32 { sd, } sn , sm vfms{ cond }.f32 { sd, } sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination register. sn, sm are the operand registers.
163 sam4cp [datasheet] 43051e?atpl?08/14 operation the vfma instruction: 1. multiplies the floating-point values in the operand registers. 2. accumulates the results into the destination register. the result of the multiply is not rounded before the accumulation. the vfms instruction: 1. negates the first operand register. 2. multiplies the floating-point values of the first and second operand registers. 3. adds the products to the destination register. 4. places the results in the destination register. the result of the multiply is not rounded before the addition. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.9 vfnma, vfnms floating-point fused negate multiply accumulate and subtract. syntax vfnma{ cond }.f32 { sd, } sn , sm vfnms{ cond }.f32 { sd, } sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination register. sn, sm are the operand registers. operation the vfnma instruction: 1. negates the first floating-point operand register. 2. multiplies the first floating-point operand with second floating-point operand. 3. adds the negation of the floating -point destination register to the product. 4. places the result into the destination register. the result of the multiply is not rounded before the addition. the vfnms instruction: 1. multiplies the first floating-point operand with second floating-point operand. 2. adds the negation of the floating-point value in the destination register to the product. 3. places the result in the destination register. the result of the multiply is not rounded before the addition. restrictions there are no restrictions. condition flags these instructions do not change the flags.
164 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11.10 vldm floating-point load multiple syntax vldm{ mode }{ cond }{. size } rn { ! }, list where: mode is the addressing mode: - ia increment after. the consecutive addresses start at the address specified in rn . - db decrement before. the consecutive addresses end just before the address specified in rn . cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. rn is the base register. the sp can be used. ! is the command to the instruction to write a modified value back to rn . this is required if mode == db, and is optional if mode == ia. list is the list of extension registers to be loaded, as a list of consecutively numbered doubleword or single word registers, separated by commas and surrounded by brackets. operation this instruction loads: ? multiple extension registers from consecutive memory locations using an address from an arm core register as the base address. restrictions the restrictions are: ? if size is present, it must be equal to the size in bits, 32 or 64, of the registers in list . ? for the base address, the sp can be used. in the arm instruction set, if ! is not specified the pc can be used. ? list must contain at least one register. if it contains doubleword registers, it must not contain more than 16 registers. ? if using the decrement before addressing mode, the write back flag, ! , must be appended to the base register specification. condition flags these instructions do not change the flags. 12.6.11.11 vldr loads a single extension register from memory syntax vldr{ cond }{. 64 } dd , [ rn {# imm }] vldr{ cond }{. 64 } dd , label vldr{ cond }{. 64 } dd , [pc, # imm }] vldr{ cond }{. 32 } sd , [ rn {, # imm }] vldr{ cond }{. 32 } sd , label vldr{ cond }{. 32 } sd , [pc, # imm ] where: cond is an optional condition code, see ?conditional execution? . 64, 32 are the optional data size specifiers. dd is the destination register for a doubleword load. sd is the destination register for a singleword load. rn is the base register. the sp can be used.
165 sam4cp [datasheet] 43051e?atpl?08/14 imm is the + or - immediate offset used to form the address. permitted address values are multiples of 4 in the range 0 to 1020. label is the label of the literal data item to be loaded. operation this instruction: ? loads a single extension register from memory, using a base address from an arm core register, with an optional offset. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.12 vlma, vlms multiplies two floating-point values, and accumulates or subtracts the results. syntax vlma {cond }.f32 sd , sn , sm vlms {cond }.f32 sd , sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sn, sm are the operand floating-point values. operation the floating-point multiply accumulate instruction: 1. multiplies two floating-point values. 2. adds the results to the destination floating-point value. the floating-point multiply subtract instruction: 1. multiplies two floating-point values. 2. subtracts the products from the destination floating-point value. 3. places the results in the destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.13 vmov immediate move floating-point immediate syntax vmov{ cond }.f32 sd , # imm where: cond is an optional condition code, see ?conditional execution? . sd is the branch destination. imm is a floating-point constant.
166 sam4cp [datasheet] 43051e?atpl?08/14 operation this instruction copies a constant value to a floating-point register. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.14 vmov register copies the contents of one register to another. syntax vmov{ cond }.f64 dd , dm vmov{ cond }.f32 sd , sm where: cond is an optional condition code, see ?conditional execution? . dd is the destination register, for a doubleword operation. dm is the source register, for a doubleword operation. sd is the destination register, for a singleword operation. sm is the source register, for a singleword operation. operation this instruction copies the contents of one floating-point register to another. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.15 vmov scalar to arm core register transfers one word of a doubleword floating-point register to an arm core register. syntax vmov{ cond } rt , dn [ x ] where: cond is an optional condition code, see ?conditional execution? . rt is the destination arm core register. dn is the 64-bit doubleword register. x specifies which half of the doubleword register to use: - if x is 0, use lower half of doubleword register. - if x is 1, use upper half of doubleword register. operation this instruction transfers: ? one word from the upper or lower half of a doubleword floating-point register to an arm core register. restrictions rt cannot be pc or sp. condition flags these instructions do not change the flags.
167 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11.16 vmov arm core register to single precision transfers a single-precision register to and from an arm core register. syntax vmov{ cond } sn , rt vmov{ cond } rt , sn where: cond is an optional condition code, see ?conditional execution? . sn is the single-precision floating-point register. rt is the arm core register. operation this instruction transfers: ? the contents of a single-precision register to an arm core register. ? the contents of an arm core register to a single-precision register. restrictions rt cannot be pc or sp. condition flags these instructions do not change the flags. 12.6.11.17 vmov two arm core registers to two single precision transfers two consecutively numbered single-precision registers to and from two arm core registers. syntax vmov{ cond } sm , sm1 , rt , rt2 vmov{ cond } rt , rt2 , sm , sm where: cond is an optional condition code, see ?conditional execution? . sm is the first single-precision register. sm1 is the second single-precision register. this is the next single-precision register after sm . rt is the arm core register that sm is transferred to or from. rt2 is the the arm core register that sm1 is transferred to or from. operation this instruction transfers: ? the contents of two consecutively numbered single-precision registers to two arm core registers. ? the contents of two arm core registers to a pair of single-precision registers. restrictions ? the restrictions are: ? the floating-point registers must be contiguous, one after the other. ? the arm core registers do not have to be contiguous. ? rt cannot be pc or sp. condition flags these instructions do not change the flags.
168 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11.18 vmov arm core register to scalar transfers one word to a floating-point register from an arm core register. syntax vmov{ cond }{. 32 } dd[x] , rt where: cond is an optional condition code, see ?conditional execution? . 32 is an optional data size specifier. dd[x] is the destination, where [x] defines which half of the doubleword is transferred, as follows: if x is 0, the lower half is extracted. if x is 1, the upper half is extracted. rt is the source arm core register. operation this instruction transfers one word to the upper or lower ha lf of a doubleword floating-poi nt register from an arm core register. restrictions rt cannot be pc or sp. condition flags these instructions do not change the flags. 12.6.11.19 vmrs move to arm core register from floating-point system register. syntax vmrs{ cond } rt , fpscr vmrs{ cond } apsr_nzcv , fpscr where: cond is an optional condition code, see ?conditional execution? . rt is the destination arm core register. this register can be r0-r14. apsr_nzcv transfer floating-point flags to the apsr flags. operation this instruction performs one of the following actions: ? copies the value of the fpscr to a general-purpose register. ? copies the value of the fpscr flag bits to the apsr n, z, c, and v flags . restrictions rt cannot be pc or sp. condition flags these instructions optionally change the flags: n, z, c, v.
169 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11.20 vmsr move to floating-point system register from arm core register. syntax vmsr{ cond } fpscr, rt where: cond is an optional condition code, see ?conditional execution? . rt is the general-purpose register to be transferred to the fpscr. operation this instruction moves the value of a general-purpose register to the fpscr. see ?floating-point status control regis- ter? for more information. restrictions the restrictions are: ? rt cannot be pc or sp. condition flags this instruction updates the fpscr. 12.6.11.21 vmul floating-point multiply. syntax vmul{ cond }.f32 { sd ,} sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sn, sm are the operand floating-point values. operation this instruction: 1. multiplies two floating-point values. 2. places the results in the destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.22 vneg floating-point negate. syntax vneg{ cond }.f32 sd , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sm is the operand floating-point value.
170 sam4cp [datasheet] 43051e?atpl?08/14 operation this instruction: 1. negates a floating-point value. 2. places the results in a second floating-point register. the floating-point instruction inverts the sign bit. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.23 vnmla, vnmls, vnmul floating-point multiply with negation followed by add or subtract. syntax vnmla{ cond }.f32 sd , sn , sm vnmls{ cond }.f32 sd , sn , sm vnmul{ cond }.f32 { sd ,} sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point register. sn, sm are the operand floating-point registers. operation the vnmla instruction: 1. multiplies two floating-point register values. 2. adds the negation of the floating-point value in the destination register to the negation of the product. 3. writes the result back to the destination register. the vnmls instruction: 1. multiplies two floating-point register values. 2. adds the negation of the floating-point value in the destination register to the product. 3. writes the result back to the destination register. the vnmul instruction: 1. multiplies together two floating-point register values. 2. writes the negation of the result to the destination register. restrictions there are no restrictions. condition flags these instructions do not change the flags. 12.6.11.24 vpop floating-point extension register pop. syntax vpop{ cond }{. size } list where: cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. if present, it must be equal to the size in bits, 32 or 64, of the registers in list .
171 sam4cp [datasheet] 43051e?atpl?08/14 list is the list of extension registers to be loaded, as a list of consecutively numbered doubleword or single- word registers, separated by commas and surrounded by brackets. operation this instruction loads multiple consecutive extension registers from the stack. restrictions the list must contain at least one register, and not more than sixteen registers. condition flags these instructions do not change the flags. 12.6.11.25 vpush floating-point extension register push. syntax vpush{ cond }{. size } list where: cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. if present, it must be equal to the size in bits, 32 or 64, of the registers in list . list is a list of the extension registers to be stored, as a list of consecutively numbered doubleword or single- word registers, separated by commas and sur rounded by brackets. operation this instruction: ? stores multiple consecutive extension registers to the stack. restrictions the restrictions are: ? list must contain at least one register, and not more than sixteen. condition flags these instructions do not change the flags. 12.6.11.26 vsqrt floating-point square root. syntax vsqrt{ cond }.f32 sd , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sm is the operand floating-point value. operation this instruction: ? calculates the square root of the value in a floating-point register. ? writes the result to another floating-point register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
172 sam4cp [datasheet] 43051e?atpl?08/14 12.6.11.27 vstm floating-point store multiple. syntax vstm{ mode }{ cond }{. size } rn { ! }, list where: mode is the addressing mode: - ia increment after. the consecutive addresses start at the address specified in rn . this is the default and can be omitted. - db decrement before. the consecutive addresses end just before the address specified in rn . cond is an optional condition code, see ?conditional execution? . size is an optional data size specifier. if present, it must be equal to the size in bits, 32 or 64, of the registers in list . rn is the base register. the sp can be used. ! is the function that causes the instruction to write a modified value back to rn . required if mode == db. list is a list of the extension registers to be stored, as a list of consecutively numbered doubleword or single- word registers, separated by commas and surrounded by brackets. operation this instruction: ? stores multiple extension registers to consecutive memory locations using a base address from an arm core register. restrictions the restrictions are: ? list must contain at least one register. if it contains doubleword registers it must not contain more than 16 registers. ? use of the pc as rn is deprecated. condition flags these instructions do not change the flags. 12.6.11.28 vstr floating-point store. syntax vstr{ cond }{. 32 } sd , [ rn {, # imm }] vstr{ cond }{. 64 } dd , [ rn {, # imm }] where cond is an optional condition code, see ?conditional execution? . 32, 64 are the optional data size specifiers. sd is the source register for a singleword store. dd is the source register for a doubleword store. rn is the base register. the sp can be used. imm is the + or - immediate offset used to form the address. values are multiples of 4 in the range 0-1020. imm can be omitted, meaning an offset of +0.
173 sam4cp [datasheet] 43051e?atpl?08/14 operation this instruction: ? stores a single extension register to memory, using an address from an arm core register, with an optional offset, defined in imm . restrictions the restrictions are: ? the use of pc for rn is deprecated. condition flags these instructions do not change the flags. 12.6.11.29 vsub floating-point subtract. syntax vsub{ cond }.f32 { sd ,} sn , sm where: cond is an optional condition code, see ?conditional execution? . sd is the destination floating-point value. sn, sm are the operand floating-point value. operation this instruction: 1. subtracts one floating-point value from another floating-point value. 2. places the results in the destination floating-point register. restrictions there are no restrictions. condition flags these instructions do not change the flags.
174 sam4cp [datasheet] 43051e?atpl?08/14 12.6.12 miscellaneous instructions the table below shows the remaining cortex-m4 instructions: 12.6.12.1 bkpt breakpoint. syntax bkpt # imm where: imm is an expression evaluating to an integer in the range 0-255 (8-bit value). operation the bkpt instruction causes the processor to enter debug stat e. debug tools can use this to investigate system state when the instruction at a particular address is reached. imm is ignored by the processor. if required, a debugger can use it to store additional information about the breakpoint. the bkpt instruction can be placed inside an it block, but it executes unconditionally, unaffected by the condition specified by the it instruction. condition flags this instruction does not change the flags. examples bkpt 0xab ; breakpoint with immediate value set to 0xab (debugger can ; extract the immediate value by locating it using the pc) note: arm does not recommend the use of the bkpt instruction with an immediate value set to 0xab for any purpose other than semi-hosting. table 12-28. miscellaneous instructions mnemonic description bkpt breakpoint cpsid change processor state, disable interrupts cpsie change processor state, enable interrupts dmb data memory barrier dsb data synchronization barrier isb instruction synchronization barrier mrs move from special register to register msr move from register to special register nop no operation sev send event svc supervisor call wfe wait for event wfi wait for interrupt
175 sam4cp [datasheet] 43051e?atpl?08/14 12.6.12.2 cps change processor state. syntax cps effect iflags where: effect is one of: ie clears the special purpose register. id sets the special purpose register. iflags is a sequence of one or more flags: i set or clear primask. f set or clear faultmask. operation cps changes the primask and faultmask special register values. see ?exception mask registers? for more information about these registers. restrictions the restrictions are: ? use cps only from privileged software, it has no effect if used in unprivileged software. ? cps cannot be conditional and so must not be used inside an it block. condition flags this instruction does not change the condition flags. examples cpsid i ; disable interrupts and configurable fault handlers (set primask) cpsid f ; disable interrupts and all fault handlers (set faultmask) cpsie i ; enable interrupts and configurable fault handlers (clear primask) cpsie f ; enable interrupts and fault handlers (clear faultmask) 12.6.12.3 dmb data memory barrier. syntax dmb{ cond } where: cond is an optional condition code, see ?conditional execution? . operation dmb acts as a data memory barrier. it ensures that all explicit memory accesses that appear, in program order, before the dmb instruction are completed before any explicit memory accesses that appear, in program order, after the dmb instruction. dmb does not affect the ordering or execution of instructions that do not access memory. condition flags this instruction does not change the flags. examples dmb ; data memory barrier
176 sam4cp [datasheet] 43051e?atpl?08/14 12.6.12.4 dsb data synchronization barrier. syntax dsb{ cond } where: cond is an optional condition code, see ?conditional execution? . operation dsb acts as a special data synchronization memory barrier. instructions that come after the dsb, in program order, do not execute until the dsb instruction completes. the dsb instruction completes when all explicit memory accesses before it complete. condition flags this instruction does not change the flags. examples dsb ; data synchronisation barrier 12.6.12.5 isb instruction synchronization barrier. syntax isb{ cond } where: cond is an optional condition code, see ?conditional execution? . operation isb acts as an instruction synchronization barrier. it flushes the pipeline of the processor, so that all instructions followin g the isb are fetched from memory again, after the isb instruction has been completed. condition flags this instruction does not change the flags. examples isb ; instruction synchronisation barrier 12.6.12.6 mrs move the contents of a special register to a general-purpose register. syntax mrs{ cond } rd , spec_reg where: cond is an optional condition code, see ?conditional execution? . rd is the destination register. spec_reg can be any of: apsr, ipsr, epsr, iepsr, iapsr, eapsr, psr, msp, psp, primask, basepri, basepri_max, faultmask, or control. operation use mrs in combination with msr as part of a read-modify-write sequence for updating a psr, for example to clear the q flag. in process swap code, the programmers model state of the process being swapped out must be saved, including relevant psr contents. similarly, the state of the process being swapped in must also be restored. these operations use mrs in the state-saving instruction sequence and msr in the state-restoring instruction sequence. note: basepri_max is an alias of basepri when used with the mrs instruction. see ?msr? .
177 sam4cp [datasheet] 43051e?atpl?08/14 restrictions rd must not be sp and must not be pc. condition flags this instruction does not change the flags. examples mrs r0, primask ; read primask value and write it to r0 12.6.12.7 msr move the contents of a general-purpose register into the specified special register. syntax msr{ cond } spec_reg , rn where: cond is an optional condition code, see ?conditional execution? . rn is the source register. spec_reg can be any of: apsr, ipsr, epsr, iepsr, iapsr, eapsr, psr, msp, psp, primask, basepri, basepri_max, faultmask, or control. operation the register access operation in msr depends on the privilege level. unprivileged software can only access the apsr. see ?application program status register? . privileged software can access all special registers. in unprivileged software writes to unallocated or execution state bits in the psr are ignored. note: when the user writes to basepri_max, the instruction writes to basepri only if either: rn is non-zero and the current basepri value is 0. rn is non-zero and less than the current basepri value. see ?mrs? . restrictions rn must not be sp and must not be pc. condition flags this instruction updates the flags explicitly based on the value in rn . examples msr control, r1 ; read r1 value and write it to the control register 12.6.12.8 nop no operation. syntax nop{ cond } where: cond is an optional condition code, see ?conditional execution? . operation nop does nothing. nop is not necessarily a time-consuming nop. the processor might remove it from the pipeline before it reaches the execution stage. use nop for padding, for example to place the following instruction on a 64-bit boundary. condition flags this instruction does not change the flags. examples nop ; no operation
178 sam4cp [datasheet] 43051e?atpl?08/14 12.6.12.9 sev send event. syntax sev{ cond } where: cond is an optional condition code, see ?conditional execution? . operation sev is a hint instruction that causes an event to be signaled to all processors within a multiprocessor system. it also sets the local event register to 1, see ?power management? . condition flags this instruction does not change the flags. examples sev ; send event 12.6.12.10 svc supervisor call. syntax svc{ cond } # imm where: cond is an optional condition code, see ?conditional execution? . imm is an expression evaluating to an integer in the range 0-255 (8-bit value). operation the svc instruction causes the svc exception. imm is ignored by the processor. if required, it can be retrieved by the exception handler to determine what service is being requested. condition flags this instruction does not change the flags. examples svc 0x32 ; supervisor call (svc handler can extract the immediate value ; by locating it via the stacked pc) 12.6.12.11 wfe wait for event. syntax wfe{ cond } where: cond is an optional condition code, see ?conditional execution? . operation wfe is a hint instruction. if the event register is 0, wfe suspends execution until one of the following events occurs: ? an exception, unless masked by the exception mask registers or the current priority level. ? an exception enters the pending state, if sevonpend in the system control register is set. ? a debug entry request, if debug is enabled. ? an event signaled by a peripheral or another processor in a multiprocessor system using the sev instruction.
179 sam4cp [datasheet] 43051e?atpl?08/14 if the event register is 1, wfe clears it to 0 and returns immediately. for more information, see ?power management? . condition flags this instruction does not change the flags. examples wfe ; wait for event 12.6.12.12 wfi wait for interrupt. syntax wfi{ cond } where: cond is an optional condition code, see ?conditional execution? . operation wfi is a hint instruction that suspends execution until one of the following events occurs: ? an exception. ? a debug entry request, regardless of whether debug is enabled. condition flags this instruction does not change the flags. examples wfi ; wait for interrupt 12.7 cortex-m4 core peripherals 12.7.1 peripherals ? nested vectored interrupt controller (nvic) the nested vectored interrupt controller (nvic) is an embedded interrupt controller that supports low latency interrupt processing. see section 12.8 ?nested vectored interrupt controller (nvic)? ? system control block (scb) the system control block (scb) is the programmers model interface to the processor. it provides system implementation information and system control, including configuration, control, and reporting of system exceptions. see section 12.9 ?system control block (scb)? ? system timer (systick) the system timer, systick, is a 24-bit count-down timer. use this as a real time operating system (rtos) tick timer or as a simple counter. see section 12.10 ?system timer (systick)? ? memory protection unit (mpu) the memory protection unit (mpu) improves system reliability by defining the memory attributes for different memory regions. it provides up to eight different regions, and an optional predefined background region. see section 12.11 ?memory protection unit (mpu)? ? floating-point unit (fpu) the floating-point unit (fpu) provides ieee754-compliant operations on single-precision, 32-bit, floating-point values. see section 12.12 ?floating point unit (fpu)?
180 sam4cp [datasheet] 43051e?atpl?08/14 12.7.2 address map the address map of the private peripheral bus (ppb) is given in the following table: in register descriptions: ? the required privilege gives the privilege level required to access the register, as follows: ? privileged: only privileged software can access the register. ? unprivileged: both unprivileged and privileged software can access the register. 12.8 nested vectored interrupt controller (nvic) this section describes the nvic and the registers it uses. the nvic supports: ? 1 to 41 interrupts. ? a programmable priority level of 0-15 for each interrupt. a higher level corresponds to a lower priority, so level 0 is the highest interrupt priority. ? level detection of interrupt signals. ? dynamic reprioritization of interrupts. ? grouping of priority values into group priority and subpriority fields. ? interrupt tail-chaining. ? an external non-maskable interrupt (nmi). the processor automatically stacks its state on exception entry and unstacks this state on exception exit, with no instruction overhead. this provides low latency exception handling. 12.8.1 level-sensitive interrupts the processor supports level-sensitive interrupts. a level-sensitive interrupt is held asserted until the peripheral deasserts the interrupt signal. typically, this happens becaus e the isr accesses the peripheral, causing it to clear the interrupt request. when the processor enters the isr, it automatically removes the pending state from the interrupt (see ?hardware and software control of interrupts? ). for a level-sensitive interrupt, if the signal is not deasserted before the processor returns from the isr, the interrupt becomes pending again, and the processor must execute its isr again. this means that the peripheral can hold the interrupt signal asserted until it no longer requires servicing. 12.8.1.1 hardware and software control of interrupts the cortex-m4 latches all interrupts. a peripheral interrupt becomes pending for one of the following reasons: ? the nvic detects that the interrupt signal is high and the interrupt is not active. ? the nvic detects a rising edge on the interrupt signal. ? a software writes to the corresponding interrupt set-pending register bit, see ?interrupt set-pending registers? , or to the nvic_stir to make an interrupt pending, see ?software trigger interrupt register? . table 12-29. core peripheral register regions address core peripheral 0xe000e008 - 0xe000e00f system control block 0xe000e010 - 0xe000e01f system timer 0xe000e100 - 0xe000e4ef nested vectored interrupt controller 0xe000ed00 - 0xe000ed3f system control block 0xe000ed90 - 0xe000edb8 memory protection unit 0xe000ef00 - 0xe000ef03 nested vectored interrupt controller 0xe000ef30 - 0xe000ef44 floating-point unit
181 sam4cp [datasheet] 43051e?atpl?08/14 a pending interrupt remains pending until one of the following: ? the processor enters the isr for the interrupt. this changes the state of the interrupt from pending to active. then: ? for a level-sensitive interrupt, when the processor returns from the isr, the nvic samples the interrupt signal. if the signal is asserted, the state of the interrupt changes to pending, which might cause the processor to immediately re-enter the isr. otherwise, the state of the interrupt changes to inactive. ? software writes to the corresponding interrupt clear-pending register bit. for a level-sensitive interrupt, if the interrupt signal is still asserted, the state of the interrupt does not change. otherwise, the state of the interrupt changes to inactive. 12.8.2 nvic design hints and tips ensure that the software uses correctly aligned register accesses. the processor does not support unaligned accesses to nvic registers. see the individual register descriptions for the supported access sizes. a interrupt can enter a pending state even if it is disabled. disabling an interrupt only prevents the processor from taking that interrupt. before programming scb_vtor to relocate the vector table, ensure that the vector table entries of the new vector table are set up for fault handlers, nmi and all enabled exception like interrupts. for more information, see the ?vector table offset register? . 12.8.2.1 nvic programming hints the software uses the cpsie i and cpsid i instructions to enable and disable the interrupts. the cmsis provides the following intrinsic functions for these instructions: void __disable_irq(void) // disable interrupts void __enable_irq(void) // enable interrupts in addition, the cmsis provides a number of functions for nvic control, including: the input parameter irqn is the irq number. for more information about these functions, see the cmsis documentation. to improve software efficiency, the cmsis simplifies the nvic register presentation. in the cmsis: ? the set-enable, clear-enable, set-pending, clear-pending and active bit registers map to arrays of 32-bit integers, so that: ? the array iser[0] to iser[1] corresponds to the registers iser0 - iser1. ? the array icer[0] to icer[1] corresponds to the registers icer0 - icer1. ? the array ispr[0] to ispr[1] corresponds to the registers ispr0 - ispr1. ? the array icpr[0] to icpr[1] corresponds to the registers icpr0 - icpr1. ? the array iabr[0] to iabr[1] corresponds to the registers iabr0 - iabr1. table 12-30. cmsis functions for nvic control cmsis interrupt control function description void nvic_setprioritygrouping(uint32_t priority_grouping) set the priority grouping void nvic_enableirq(irqn_t irqn) enable irqn void nvic_disableirq(irqn_t irqn) disable irqn uint32_t nvic_getpendingirq (irqn_t irqn) return true (irq-number) if irqn is pending void nvic_setpendingirq (irqn_t irqn) set irqn pending void nvic_clearpendingirq (irqn_t irqn) clear irqn pending status uint32_t nvic_getactive (irqn_t irqn) return the irq number of the active interrupt void nvic_setpriority (irqn_t irqn, uint32_t priority) set priority for irqn uint32_t nvic_getpriority (irqn_t irqn) read priority of irqn void nvic_systemreset (void) reset the system
182 sam4cp [datasheet] 43051e?atpl?08/14 ? the interrupt priority registers (ipr0-ipr10) provide an 8-bit priority field for each interrupt and each register holds four priority fields. the cmsis provides thread-safe code that gives atomic access to the interrupt priority registers. table 12-31 shows how the interrupts, or irq numbers, map onto the interrupt registers and corresponding cmsis variables that have one bit per interrupt. note: 1. each array element corresponds to a single nvic register, for example the icer[0] element corresponds to the icer0. 12.8.3 nested vectored interrupt controller (nvic) user interface table 12-31. mapping of interrupts to the interrupt variables interrupts cmsis array elements (1) set-enable clear-enable set-pending clear-pending active bit 0 - 31 iser[0] icer[0] ispr[0] icpr[0] iabr[0] 32 - 41 iser[1] icer[1] ispr[1] icpr[1] iabr[1] table 12-32. nested vectored interrupt controller (nvic) register mapping offset register name access reset 0xe000e100 interrupt set-enable register 0 nvic_iser0 read/write 0x00000000 ... ... ... ... ... 0xe000e11c interrupt set-enable register 7 nvic_iser7 read/write 0x00000000 0xe000e180 interrupt clear-enable register 0 nvic_icer0 read/write 0x00000000 ... ... ... ... ... 0xe000e19c interrupt clear-enable register 7 nvic_icer7 read/write 0x00000000 0xe000e200 interrupt set-pending register 0 nvic_ispr0 read/write 0x00000000 ... ... ... ... ... 0xe000e21c interrupt set-pending register 7 nvic_ispr7 read/write 0x00000000 0xe000e280 interrupt clear-pending register 0 nvic_icpr0 read/write 0x00000000 ... ... ... ... ... 0xe000e29c interrupt clear-pending register 7 nvic_icpr7 read/write 0x00000000 0xe000e300 interrupt active bit register 0 nvic_iabr0 read/write 0x00000000 ... ... ... ... ... 0xe000e31c interrupt active bit register 7 nvic_iabr7 read/write 0x00000000 0xe000e400 interrupt priority register 0 nvic_ipr0 read/write 0x00000000 ... ... ... ... ... 0xe000e426 interrupt priority register 10 nvic_ipr10 read/write 0x00000000 0xe000ef00 software trigger interrupt register nvic_stir write-only 0x00000000
183 sam4cp [datasheet] 43051e?atpl?08/14 12.8.3.1 interrupt set-enable registers name: nvic_iserx [x=0..7] access: read/write reset: 0x00000000 these registers enable interrupts and show which interrupts are enabled. ? setena: interrupt set-enable write: 0: no effect. 1: enables the interrupt. read: 0: interrupt disabled. 1: interrupt enabled. notes: 1. if a pending interrupt is enabled, the nvic activates the interrupt based on its priority. 2. if an interrupt is not enabled, asserting its interrupt signal changes the interrupt state to pending, the nvic never activates the interrupt, regardless of its priority. 31 30 29 28 27 26 25 24 setena 23 22 21 20 19 18 17 16 setena 15 14 13 12 11 10 9 8 setena 76543210 setena
184 sam4cp [datasheet] 43051e?atpl?08/14 12.8.3.2 interrupt clear-enable registers name: nvic_icerx [x=0..7] access: read/write reset: 0x00000000 these registers disable interrupts, and show which interrupts are enabled. ? clrena: interrupt clear-enable write: 0: no effect. 1: disables the interrupt. read: 0: interrupt disabled. 1: interrupt enabled. 31 30 29 28 27 26 25 24 clrena 23 22 21 20 19 18 17 16 clrena 15 14 13 12 11 10 9 8 clrena 76543210 clrena
185 sam4cp [datasheet] 43051e?atpl?08/14 12.8.3.3 interrupt set-pending registers name: nvic_isprx [x=0..7] access: read/write reset: 0x00000000 these registers force interrupts into the pending state, and show which interrupts are pending. ? setpend: interrupt set-pending write: 0: no effect. 1: changes the interrupt state to pending. read: 0: interrupt is not pending. 1: interrupt is pending. notes: 1. writing a 1 to an ispr bit corresponding to an interrupt that is pending has no effect. 2. writing a 1 to an ispr bit corresponding to a disabled interrupt sets the state of that interrupt to pending. 31 30 29 28 27 26 25 24 setpend 23 22 21 20 19 18 17 16 setpend 15 14 13 12 11 10 9 8 setpend 76543210 setpend
186 sam4cp [datasheet] 43051e?atpl?08/14 12.8.3.4 interrupt clear-pending registers name: nvic_icprx [x=0..7] access: read/write reset: 0x00000000 these registers remove the pending state from interrupts, and show which interrupts are pending. ? clrpend: interrupt clear-pending write: 0: no effect. 1: removes the pending state from an interrupt. read: 0: interrupt is not pending. 1: interrupt is pending. note: writing a 1 to an icpr bit does not affect the active state of the corresponding interrupt. 31 30 29 28 27 26 25 24 clrpend 23 22 21 20 19 18 17 16 clrpend 15 14 13 12 11 10 9 8 clrpend 76543210 clrpend
187 sam4cp [datasheet] 43051e?atpl?08/14 12.8.3.5 interrupt active bit registers name: nvic_iabrx [x=0..7] access: read/write reset: 0x00000000 these registers indicate which interrupts are active. ? active: interrupt active flags 0: interrupt is not active. 1: interrupt is active. note: a bit reads as one if the status of the corresponding interrupt is active, or active and pending. 31 30 29 28 27 26 25 24 active 23 22 21 20 19 18 17 16 active 15 14 13 12 11 10 9 8 active 76543210 active
188 sam4cp [datasheet] 43051e?atpl?08/14 12.8.3.6 interrupt priority registers name: nvic_iprx [x=0..10] access: read/write reset: 0x00000000 the nvic_ipr0-nvic_ipr10 registers provide a 8-bit priority field for each interrupt. these registers are byte-accessible. each register holds four priority fields, that map up to four elements in the cmsis interrupt priority array ip[0] to ip[40]. ? pri3: priority (4m+3) priority, byte offset 3, refers to register bits [31:24]. ? pri2: priority (4m+2) priority, byte offset 2, refers to register bits [23:16]. ? pri1: priority (4m+1) priority, byte offset 1, refers to register bits [15:8]. ? pri0: priority (4m) priority, byte offset 0, refers to register bits [7:0]. notes: 1. each priority field holds a priority value, 0- 15 . the lower the value, the greater the priority of the corresponding interrupt. the processor implements only bits[7:4] of each field; bits[3:0] read as zero and ignore writes. 2. for more information about the ip[0] to ip[ 40 ] interrupt priority array, that provides the software view of the interrupt priorities, see table 12-30, ?cmsis functions for nvic control? . 3. the corresponding ipr number n is given by n = m div 4. 4. the byte offset of the required priority field in this register is m mod 4. 31 30 29 28 27 26 25 24 pri3 23 22 21 20 19 18 17 16 pri2 15 14 13 12 11 10 9 8 pri1 76543210 pri0
189 sam4cp [datasheet] 43051e?atpl?08/14 12.8.3.7 software trigger interrupt register name: nvic_stir access: write-only reset: 0x00000000 write to this register to generate an interrupt from the software. ? intid: interrupt id interrupt id of the interrupt to trigger, in the range 0-239. for example, a value of 0x03 specifies interrupt irq3. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ??????? intid 76543210 intid
190 sam4cp [datasheet] 43051e?atpl?08/14 12.9 system control block (scb) the system control block (scb) provides system implementation information, and system control. this includes configuration, control, and reporting of the system exceptions. ensure that the software uses aligned accesses of the correct size to access the system control block registers: ? except for the scb_cfsr and scb_shpr1-scb_shpr3 registers, it must use aligned word accesses. ? for the scb_cfsr and scb_shpr1-scb_shpr3 registers, it can use byte or aligned halfword or word accesses. the processor does not support unaligned accesses to system control block registers. in a fault handler, to determine the true faulting address: 1. read and save the mmfar or scb_bfar value. 2. read the mmarvalid bit in the mmfsr subregister, or the bfarvalid bit in the bfsr subregister. the scb_mmfar or scb_bfar address is valid only if this bit is 1. the software must follow this sequence because another higher priority exception might change the scb_mmfar or scb_bfar value. for example, if a higher priority handler preempts the current fault handler, the other fault might change the scb_mmfar or scb_bfar value. 12.9.1 system control block (scb) user interface notes: 1. see the register description for more information. 2. this register contains the subregisters: ?mmfsr: memory management fault status subregister? (0xe000ed28 - 8 bits), ?bfsr: bus fault status subregister? (0xe000ed29 - 8 bits), ?ufsr: usage fault status subregister? (0xe000ed2a - 16 bits). table 12-33. system control block (scb) register mapping offset register name access reset 0xe000e008 auxiliary control register scb_actlr read/write 0x00000000 0xe000ed00 cpuid base register scb_cpuid read-only 0x410fc240 0xe000ed04 interrupt control and state register scb_icsr read/write (1) 0x00000000 0xe000ed08 vector table offset register scb_vtor read/write 0x00000000 0xe000ed0c application interrupt and reset control register scb_aircr read/write 0xfa050000 0xe000ed10 system control register scb_scr read/write 0x00000000 0xe000ed14 configuration and control register scb_ccr read/write 0x00000200 0xe000ed18 system handler priority register 1 scb_shpr1 read/write 0x00000000 0xe000ed1c system handler priority register 2 scb_shpr2 read/write 0x00000000 0xe000ed20 system handler priority register 3 scb_shpr3 read/write 0x00000000 0xe000ed24 system handler control and state register scb_shcsr read/write 0x00000000 0xe000ed28 configurable fault status register scb_cfsr (2) read/write 0x00000000 0xe000ed2c hardfault status register scb_hfsr read/write 0x00000000 0xe000ed34 memmanage fault address register scb_mmfar read/write unknown 0xe000ed38 busfault address register scb_bfar read/write unknown 0xe000ed3c auxiliary fault status register scb_afsr read/write 0x00000000
191 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.1 auxiliary control register name: scb_actlr access: read/write the scb_actlr register provides disable bits for the following processor functions: ? it folding. ? write buffer use for accesses to the default memory map. ? interruption of multi-cycle instructions. by default, this register is set to provide optimum performance from the cortex-m4 processor, and does not normally require modification. ? disoofp: disable out of order floating point disables floating point instructions that complete out of order with respect to integer instructions. ? disfpca: disable fpca disables an automatic update of control.fpca. ? disfold: disable folding when set to 1, disables the it folding. note: in some situations, the processor can start executing the first instruction in an it block while it is still executing the it instruction. this behavior is called it folding, and it improves the performance. however, it folding can cause jitter in looping. if a task must avoid jitter, set the disfold bit to 1 before executing the task, to disable the it folding. ? disdefwbuf: disable default write buffer when set to 1, it disables the write buffer use during default memory map accesses. this causes busfault to be precise but decreases the performance, as any store to memory must complete before the processor can execute the next instruction. this bit only affects write buffers implemented in the cortex-m4 processor. ? dismcycint: disable multiple cycle interruption when set to 1, it disables the interruption of load multiple and store multiple instructions. this increases the interrupt late ncy of the processor, as any ldm or stm must complete before the processor can stack the current state and enter the interrupt handler. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? disoofp disfpca 7654 3 2 1 0 ? disfold disdefwbuf dismcycint
192 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.2 cpuid base register name: scb_cpuid access: read/write the scb_cpuid register contains the processor part number, version, and implementation information. ? implementer: implementer code 0x41: arm. ? variant: variant number it is the r value in the rnpn product revision identifier: 0x0: revision 0. ? constant reads as 0xf. ? partno: part number of the processor 0xc24 = cortex-m4. ? revision: revision number it is the p value in the rnpn product revision identifier: 0x0: patch 0. 31 30 29 28 27 26 25 24 implementer 23 22 21 20 19 18 17 16 variant constant 15 14 13 12 11 10 9 8 partno 76543210 partno revision
193 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.3 interrupt control and state register name: scb_icsr access: read/write the scb_icsr register provides a set-pending bit for the non-maskable interrupt (nmi) exception, and set-pending and clear-pending bits for the pendsv and systick exceptions. it indicates: ? the exception number of the exception being processed, and whether there are preempted active exceptions. ? the exception number of the highest priority pending exception, and whether any interrupts are pending. ? nmipendset: nmi set-pending write: pendsv set-pending bit. write: 0: no effect. 1: changes nmi exception state to pending. read: 0: nmi exception is not pending. 1: nmi exception is pending. as nmi is the highest-priority exception, the processor normally enters the nmi exception handler as soon as it registers a wri te of 1 to this bit. entering the handler clears this bit to 0. a read of this bit by the nmi exception handler returns 1 only if the nmi signal is reasserted while the processor is executing that handler. ? pendsvset: pendsv set-pending write: 0: no effect. 1: changes pendsv exception state to pending. read: 0: pendsv exception is not pending. 1: pendsv exception is pending. writing 1 to this bit is the only way to set the pendsv exception state to pending. 31 30 29 28 27 26 25 24 nmipendset ? pendsvset pendsvclr pendstset pendstclr ? 23 22 21 20 19 18 17 16 ? isrpending vectpending 15 14 13 12 11 10 9 8 vectpending rettobase ? vectactive 76543210 vectactive
194 sam4cp [datasheet] 43051e?atpl?08/14 ? pendsvclr: pendsv clear-pending write: 0: no effect. 1: removes the pending state from the pendsv exception. ? pendstset: systick exception set-pending write: 0: no effect. 1: changes systick exception state to pending. read: 0: systick exception is not pending. 1: systick exception is pending. ? pendstclr: systick exception clear-pending write: 0: no effect. 1: removes the pending state from the systick exception. this bit is write-only. on a register read, its value is unknown. ? isrpending: interrupt pending flag (excluding nmi and faults) 0: interrupt not pending. 1: interrupt pending. ? vectpending: exception number of the highest priority pending enabled exception 0: no pending exceptions. nonzero: the exception number of the highest priority pending enabled exception. the value indicated by this field includes the effect of the basepri and faultmask registers, but not any effect of the primask register. ? rettobase: preempted active exceptions present or not 0: there are preempted active exceptions to execute. 1: there are no active exceptions, or the currently-executing exception is the only active exception. ? vectactive: active exception number contained 0: thread mode. nonzero: the exception number of the currently active exception. the value is the same as ipsr bits [8:0]. see ?interrupt program status register? . subtract 16 from this value to obtain the irq number required to index into the interrupt clear-enable, set-enable, clear-pending, set-pending, or priority registers, see ?interrupt program status register? . note: when the user writes to the scb_icsr, the effect is unpredictable if: - writing a 1 to the pendsvset bit and writing a 1 to the pendsvclr bit. - writing a 1 to the pendstset bit and writing a 1 to the pendstclr bit.
195 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.4 vector table offset register name: scb_vtor access: read/write the scb_vtor indicates the offset of the vector table base address from memory address 0x00000000. ? tbloff: vector table base offset it contains bits [29:7] of the offset of the table base from the bottom of the memory map. bit [29] determines whether the vector table is in the code or sram memory region: 0: code. 1: sram. it is sometimes called the tblbase bit. note: when setting tbloff, the offset must be aligned to the number of exception entries in the vector table. configure the next statement to give the information required for your implementation; the statement reminds the user of how to determine the alignment requirement. the minimum alignment is 32 words, enough for up to 16 interrupts. for more interrupts, adjust the alignment by rounding up to the next power of two. for example, if 21 interrupts are required, the alignment must be on a 64-word boundary because the required table size is 37 words, and the next power of two is 64. table alignment requirements mean that bits[6:0] of the table offset are always zero. 31 30 29 28 27 26 25 24 tbloff 23 22 21 20 19 18 17 16 tbloff 15 14 13 12 11 10 9 8 tbloff 76543210 tbloff ?
196 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.5 application interrupt and reset control register name: scb_aircr access: read/write the scb_aircr provides priority grouping control for the exception model, endian status for data accesses, and reset control of the system. to write to this register, write 0x5fa to the vectkey field, otherwise the processor ignores the write. ? vectkeystat: register key read: reads as 0xfa05. ? vectkey: register key write: writes 0x5fa to vectkey, otherwise the write is ignored. ? endianness: data endianness 0: little-endian. 1: big-endian. ? prigroup: interrupt priority grouping this field determines the split of group priority from subpriority. it shows the position of the binary point that splits the p ri_ n fields in the interrupt priority registers into separate group priority and subpriority fields. the table below shows how the prigroup value controls this split: note: 1. pri_n[7:0] field showing the binary point. x denotes a group priority field bit, and y denotes a subpriority field bit. determining preemption of an exception uses only the group priority field. 31 30 29 28 27 26 25 24 vectkeystat/vectkey 23 22 21 20 19 18 17 16 vectkeystat/vectkey 15 14 13 12 11 10 9 8 endianness ? prigroup 7 6543 2 1 0 ? sysresetreq vectclractive vectreset interrupt priority level value, pri_ n [7:0] number of prigroup binary point (1) group priority bits subpriority bits group priorities subpriorities 0b000 bxxxxxxx.y [7:1] none 128 2 0b001 bxxxxxx.yy [7:2] [4:0] 64 4 0b010 bxxxxx.yyy [7:3] [4:0] 32 8 0b011 bxxxx.yyyy [7:4] [4:0] 16 16 0b100 bxxx.yyyyy [7:5] [4:0] 8 32 0b101 bxx.yyyyyy [7:6] [5:0] 4 64 0b110 bx.yyyyyyy [7] [6:0] 2 128 0b111 b.yyyyyyy none [7:0] 1 256
197 sam4cp [datasheet] 43051e?atpl?08/14 ? sysresetreq: system reset request 0: no system reset request. 1: asserts a signal to the outer system that requests a reset. this is intended to force a large system reset of all major components except for debug. this bit reads as 0. ? vectclractive: reserved for debug use this bit reads as 0. when writing to the register, write 0 to this bit, otherwise the behavior is unpredictable. ? vectreset: reserved for debug use this bit reads as 0. when writing to the register, write 0 to this bit, otherwise the behavior is unpredictable.
198 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.6 system control register name: scb_scr access: read/write ? sevonpend: send event on pending bit 0: only enabled interrupts or events can wake up the processor; disabled interrupts are excluded. 1: enabled events and all interrupts, including disabled interrupts, can wake up the processor. when an event or an interrupt enters the pending state, the event signal wakes up the processor from wfe. if the processor is n ot waiting for an event, the event is registered and affects the next wfe. the processor also wakes up on execution of an sev instruction or an external event. ? sleepdeep: sleep or deep sleep controls whether the processor uses sleep or deep sleep as its low-power mode: 0: sleep. 1: deep sleep. ? sleeponexit: sleep-on-exit indicates sleep-on-exit when returning from the handler mode to the thread mode: 0: do not sleep when returning to thread mode. 1: enter sleep, or deep sleep, on return from an isr. setting this bit to 1 enables an interrupt-driven application to avoid returning to an empty main application. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 765432 1 0 ? sevonpend ? sleepdeep sleeponexit ?
199 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.7 configuration and control register name: scb_ccr access: read/write the scb_ccr controls the entry to the thread mode and enables the handlers for nmi, hard fault and faults escalated by faultmask to ignore busfaults. it also enables the division by zero and unaligned access trapping, and the access to the nvic_stir by unprivileged software (see ?software trigger interrupt register? ). ? stkalign: stack alignment indicates the stack alignment on exception entry: 0: 4-byte aligned. 1: 8-byte aligned. on exception entry, the processor uses bit [9] of the stacked psr to indicate the stack alignment. on return from the exception , it uses this stacked bit to restore the correct stack alignment. ? bfhfnmign: bus faults ignored enables handlers with priority -1 or -2 to ignore data bus faults caused by load and store instructions. this applies to the ha rd fault and faultmask escalated handlers: 0: data bus faults caused by load and store instructions cause a lock-up. 1: handlers running at priority -1 and -2 ignore data bus faults caused by load and store instructions. set this bit to 1 only when the handler and its data are in abs olutely safe memory. the normal use of this bit is to probe syst em devices and bridges to detect control path problems and fix them. ? div_0_trp: division by zero trap enables faulting or halting when the processor executes an sdiv or udiv instruction with a divisor of 0: 0: do not trap divide by 0. 1: trap divide by 0. when this bit is set to 0, a divide by zero returns a quotient of 0. ? unalign_trp: unaligned access trap enables unaligned access traps: 0: do not trap unaligned halfword and word accesses. 1: trap unaligned halfword and word accesses. if this bit is set to 1, an unaligned access generates a usage fault. unaligned ldm, stm, ldrd, and strd instructions always fault irrespective of whether unalign_trp is set to 1. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? stkalign bfhfnmign 7654321 0 ? div_0_trp unalign_ trp ? usersetmp end nonbasethr dena
200 sam4cp [datasheet] 43051e?atpl?08/14 ? usersetmpend: unprivileged software access enables unprivileged software access to the nvic_stir, see ?software trigger interrupt register? : 0: disable. 1: enable. ? nonbasethrdena: thread mode enable indicates how the processor enters thread mode: 0: the processor can enter the thread mode only when no exception is active. 1: the processor can enter the thread mode from any level under the control of an exc_return value, see ?exception return? .
201 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.8 system handler priority registers the scb_shpr1-scb_shpr3 registers set the priority level, 0 to 15 of the exception handlers that have configurable priority. they are byte-accessible. the system fault handlers and the priority field and register for each handler are: each pri_n field is 8 bits wide, but the processor implements only bits [7:4] of each field, and bits [3:0] read as zero and ig nore writes. table 12-34. system fault handler priority fields handler field register description memory management fault (memmanage) pri_4 ?system handler priority register 1? bus fault (busfault) pri_5 usage fault (usagefault) pri_6 svcall pri_11 ?system handler priority register 2? pendsv pri_14 ?system handler priority register 3? systick pri_15
202 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.9 system handler priority register 1 name: scb_shpr1 access: read/write ? pri_6: priority priority of system handler 6, usagefault. ? pri_5: priority priority of system handler 5, busfault. ? pri_4: priority priority of system handler 4, memmanage. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 pri_6 15 14 13 12 11 10 9 8 pri_5 76543210 pri_4
203 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.10 system handler priority register 2 name: scb_shpr2 access: read/write ? pri_11: priority priority of system handler 11, svcall. 31 30 29 28 27 26 25 24 pri_11 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ?
204 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.11 system handler priority register 3 name: scb_shpr3 access: read/write ? pri_15: priority priority of system handler 15, systick exception. ? pri_14: priority priority of system handler 14, pendsv. 31 30 29 28 27 26 25 24 pri_15 23 22 21 20 19 18 17 16 pri_14 15 14 13 12 11 10 9 8 ? 76543210 ?
205 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.12 system handler control and state register name: scb_shcsr access: read/write the shcsr enables the system handlers, and indicates the pending status of the bus fault, memory management fault, and svc exceptions; it also indicates the active status of the system handlers. ? usgfaultena: usage fault enable 0: disables the exception. 1: enables the exception. ? busfaultena: bus fault enable 0: disables the exception. 1: enables the exception. ? memfaultena: memory management fault enable 0: disables the exception. 1: enables the exception. ? svcallpended: svc call pending read: 0: the exception is not pending. 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. ? busfaultpended: bus fault exception pending read: 0: the exception is not pending. 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. ? memfaultpended: memory management fault exception pending read: 0: the exception is not pending. 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? usgfaultena busfaultena memfaultena 15 14 13 12 11 10 9 8 svcallpen ded busfaultpen ded memfaultpen ded usgfaultpen ded systickact pendsvact ? monitoract 76543210 svcallact ? usgfaultact ? busfaultact memfaultact
206 sam4cp [datasheet] 43051e?atpl?08/14 ? usgfaultpended: usage fault exception pending read: 0: the exception is not pending. 1: the exception is pending. note: the user can write to these bits to change the pending status of the exceptions. ? systickact: systick exception active read: 0: the exception is not active. 1: the exception is active. note: the user can write to these bits to change the active status of the exceptions. - caution: a software that changes the value of an active bit in this register without a correct adjustment to the stacked content can cause the processor to generate a fault exception. ensure that the software writing to this register retains and subsequently restores the current active status. - caution: after enabling the system handlers, to change the value of a bit in this register, the user must use a read-modify-write procedure to ensure that only the required bit is changed. ? pendsvact: pendsv exception active 0: the exception is not active. 1: the exception is active. ? monitoract: debug monitor active 0: debug monitor is not active. 1: debug monitor is active. ? svcallact: svc call active 0: svc call is not active. 1: svc call is active. ? usgfaultact: usage fault exception active 0: usage fault exception is not active. 1: usage fault exception is active. ? busfaultact: bus fault exception active 0: bus fault exception is not active. 1: bus fault exception is active. ? memfaultact: memory management fault exception active 0: memory management fault exception is not active. 1: memory management fault exception is active. if the user disables a system handler and the corresponding fault occurs, the processor treats the fault as a hard fault. the user can write to this register to change the pending or active status of system exceptions. an os kernel can write to the active bits to perform a context switch that changes the current exception type.
207 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.13 configurable fault status register name: scb_cfsr access: read/write ? iaccviol: instruction access violation flag this is part of ?mmfsr: memory management fault status subregister? . 0: no instruction access violation fault. 1: the processor attempted an instruction fetch from a location that does not permit execution. this fault occurs on any access to an xn region, even when the mpu is disabled or not present. when this bit is 1, the pc value stacked for the exception return points to the faulting instruction. the processor has not wri tten a fault address to the scb_mmfar. ? daccviol: data access violation flag this is part of ?mmfsr: memory management fault status subregister? . 0: no data access violation fault. 1: the processor attempted a load or store at a location that does not permit the operation. when this bit is 1, the pc value stacked for the exception return points to the faulting instruction. the processor has loaded the scb_mmfar register with the address of the attempted access. ? munstkerr: memory manager fault on unstacking for a return from exception this is part of ?mmfsr: memory management fault status subregister? . 0: no unstacking fault. 1: unstack for an exception return has caused one or more access violations. this fault is chained to the handler. this means that when this bit is 1, the original return stack is still present. the proce ssor has not adjusted the sp from the failing return, and has not performed a new save. the processor has not written a fault address to the scb_mmfar register. ? mstkerr: memory manager fault on stacking for exception entry this is part of ?mmfsr: memory management fault status subregister? . 0: no stacking fault. 1: stacking for an exception entry has caused one or more access violations. when this bit is 1, the sp is still adjusted but the values in the context area on the stack might be incorrect. the processor has not written a fault address to scb_mmfar register. 31 30 29 28 27 26 25 24 ? divbyzero unaligned 23 22 21 20 19 18 17 16 ? nocp invpc invstate undefinstr 15 14 13 12 11 10 9 8 bfarvalid ? lsperr stkerr unstkerr impreciserr preciserr ibuserr 76543210 mmarvalid ? mlsperr mstkerr munstkerr ? daccviol iaccviol
208 sam4cp [datasheet] 43051e?atpl?08/14 ? mlsperr: memmanage during lazy state preservation this is part of ?mmfsr: memory management fault status subregister? . 0: no memmanage fault occurred during the floating-point lazy state preservation. 1: a memmanage fault occurred during the floating-point lazy state preservation. ? mmarvalid: memory management fault address register (scb_mmfar) valid flag this is part of ?mmfsr: memory management fault status subregister? . 0: the value in scb_mmfar is not a valid fault address. 1: scb_mmfar register holds a valid fault address. if a memory management fault occurs and is escalated to a hard fault because of priority, the hard fault handler must set this bit to 0. this prevents problems on return to a stacked active memory management fault handler whose scb_mmfar value has been overwritten. ? ibuserr: instruction bus error this is part of ?bfsr: bus fault status subregister? . 0: no instruction bus error. 1: instruction bus error. the processor detects the instruction bus error on prefetching an instruction, but it sets the ibuserr flag to 1 only if it att empts to issue the faulting instruction. when the processor sets this bit to 1, it does not write a fault address to the bfar. ? preciserr: precise data bus error this is part of ?bfsr: bus fault status subregister? . 0: no precise data bus error. 1: a data bus error has occurred, and the pc value stacked for the exception return points to the instruction that caused the f ault. when the processor sets this bit to 1, it writes the faulting address to the scb_bfar. ? impreciserr: imprecise data bus error this is part of ?bfsr: bus fault status subregister? . 0: no imprecise data bus error. 1: a data bus error has occurred, but the return address in the stack frame is not related to the instruction that caused the e rror. when the processor sets this bit to 1, it does not write a fault address to the scb_bfar register. this is an asynchronous fault. therefore, if it is detected when the priority of the current process is higher than the bus fau lt priority, the bus fault becomes pending and becomes active only when the processor returns from all higher priority processes. if a precise fault occurs before the processor enters the handler for the imprecise bus fault, the handler detects that both this bit and one of the precise fault status bits are set to 1. ? unstkerr: bus fault on unstacking for a return from exception this is part of ?bfsr: bus fault status subregister? . 0: no unstacking fault. 1: unstack for an exception return has caused one or more bus faults. this fault is chained to the handler. this means that when the processor sets this bit to 1, the original return stack is still present. the processor does not adjust the sp from the failing return, does not performed a new save, and does not write a fault address to the bfar.
209 sam4cp [datasheet] 43051e?atpl?08/14 ? stkerr: bus fault on stacking for exception entry this is part of ?bfsr: bus fault status subregister? . 0: no stacking fault. 1: stacking for an exception entry has caused one or more bus faults. when the processor sets this bit to 1, the sp is still adjusted but the values in the context area on the stack might be incorr ect. the processor does not write a fault address to the scb_bfar. ? lsperr: bus error during lazy floating-point state preservation this is part of ?bfsr: bus fault status subregister? . 0: no bus fault occurred during floating-point lazy state preservation. 1: a bus fault occurred during floating-point lazy state preservation. ? bfarvalid: bus fault address register (bfar) valid flag this is part of ?bfsr: bus fault status subregister? . 0: the value in scb_bfar is not a valid fault address. 1: scb_bfar holds a valid fault address. the processor sets this bit to 1 after a bus fault where the address is known. other faults can set this bit to 0, such as a me mory management fault occurring later. if a bus fault occurs and is escalated to a hard fault because of priority, the hard fault handler must set this bit to 0. this prevents problems if returning to a stacked active bus fault handler whose scb_bfar value has been overwritten. ? undefinstr: undefined instruction usage fault this is part of ?ufsr: usage fault status subregister? . 0: no undefined instruction usage fault. 1: the processor has attempted to execute an undefined instruction. when this bit is set to 1, the pc value stacked for the exception return points to the undefined instruction. an undefined instruction is an instruction that the processor cannot decode. ? invstate: invalid state usage fault this is part of ?ufsr: usage fault status subregister? . 0: no invalid state usage fault. 1: the processor has attempted to execute an instruction that makes illegal use of the epsr. when this bit is set to 1, the pc value stacked for the exception return points to the instruction that attempted the illegal u se of the epsr. this bit is not set to 1 if an undefined instruction uses the epsr. ? invpc: invalid pc load usage fault this is part of ?ufsr: usage fault status subregister? . it is caused by an invalid pc load by exc_return: 0: no invalid pc load usage fault. 1: the processor has attempted an illegal load of exc_return to the pc, as a result of an invalid context, or an invalid exc_return value. when this bit is set to 1, the pc value stacked for the exception return points to the instruction that tried to perform the il legal load of the pc.
210 sam4cp [datasheet] 43051e?atpl?08/14 ? nocp: no coprocessor usage fault this is part of ?ufsr: usage fault status subregister? . the processor does not support coprocessor instructions: 0: no usage fault caused by attempting to access a coprocessor. 1: the processor has attempted to access a coprocessor. ? unaligned: unaligned access usage fault this is part of ?ufsr: usage fault status subregister? . 0: no unaligned access fault, or unaligned access trapping not enabled. 1: the processor has made an unaligned memory access. enable trapping of unaligned accesses by setting the unalign_trp bit in the scb_ccr to 1. see ?configuration and control register? . unaligned ldm, stm, ldrd, and strd instructions always fault irrespective of the setting of unalign_trp. ? divbyzero: divide by zero usage fault this is part of ?ufsr: usage fault status subregister? . 0: no divide by zero fault, or divide by zero trapping not enabled. 1: the processor has executed an sdiv or udiv instruction with a divisor of 0. when the processor sets this bit to 1, the pc value stacked fo r the exception return points to the instruction that performed t he divide by zero. enable trapping of divide by zero by setting the div_0_trp bit in the scb_ccr to 1. see ?configuration and control register? .
211 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.14 configurable fault status register (byte access) name: scb_cfsr (byte) access: read/write ? mmfsr: memory management fault status subregister the flags in the mmfsr subregister indicate the cause of memory access faults. see bitfield [7..0] description in section 12.9.1.13 . ? bfsr: bus fault status subregister the flags in the bfsr subregister indicate the cause of a bus access fault. see bitfield [14..8] description in section 12.9.1.13 . ? ufsr: usage fault status subregister the flags in the ufsr subregister indicate the cause of a usage fault. see bitfield [31..15] description in section 12.9.1.13 . note: the ufsr bits are sticky. this means that as one or more fault occurs, the associated bits are set to 1. a bit that is set to 1 is cleared to 0 only by writing a 1 to that bit, or by a reset. the scb_cfsr indicates the cause of a memory management fault, bus fault, or usage fault. it is byte accessible. the user can access the scb_cfsr or its subregisters as follows: ? access complete scb_cfsr with a word access to 0xe000ed28. ? access mmfsr with a byte access to 0xe000ed28. ? access mmfsr and bfsr with a halfword access to 0xe000ed28. ? access bfsr with a byte access to 0xe000ed29. ? access ufsr with a halfword access to 0xe000ed2a. 31 30 29 28 27 26 25 24 ufsr 23 22 21 20 19 18 17 16 ufsr 15 14 13 12 11 10 9 8 bfsr 76543210 mmfsr
212 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.15 hard fault status register name: scb_hfsr access: read/write the scb_hfsr gives information about events that activate the hard fault handler. this register is read, write to clear. this means that bits in the register read normally, but writing a 1 to any bit clears that bit to 0. ? debugevt: reserved for debug use when writing to the register, write a 0 to this bit, otherwise the behavior is unpredictable. ? forced: forced hard fault it indicates a forced hard fault, generated by escalation of a fault with configurable priority that cannot be handles, either because of priority or because it is disabled: 0: no forced hard fault. 1: forced hard fault. when this bit is set to 1, the hard fault handler must read the other fault status registers to find the cause of the fault. ? vecttbl: bus fault on a vector table it indicates a bus fault on a vector table read during an exception processing: 0: no bus fault on vector table read. 1: bus fault on vector table read. this error is always handled by the hard fault handler. when this bit is set to 1, the pc value stacked for the exception return points to the instruction that was preempted by the exception. note: the hfsr bits are sticky. this means that, as one or more fault occurs, the associated bits are set to 1. a bit that is se t to 1 is cleared to 0 only by writing a 1 to that bit, or by a reset. 31 30 29 28 27 26 25 24 debugevt forced ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? vecttbl ?
213 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.16 memmanage fault address register name: scb_mmfar access: read/write the scb_mmfar contains the address of the location that generated a memory management fault. ? address: memory management fault generation location address when the mmarvalid bit of the mmfsr subregi ster is set to 1, this field holds the address of the location that generated the memory management fault. notes: 1. when an unaligned access faults, the address is the actual address that faulted. because a single read or write instruction can be split into multiple aligned accesses, the fault address can be any address in the range of the requested access size. 2. flags in the mmfsr subregister indicate the cause of the fault, and whether the value in the scb_mmfar register is valid. see ?mmfsr: memory management fault status subregister? . 31 30 29 28 27 26 25 24 address 23 22 21 20 19 18 17 16 address 15 14 13 12 11 10 9 8 address 76543210 address
214 sam4cp [datasheet] 43051e?atpl?08/14 12.9.1.17 bus fault address register name: scb_bfar access: read/write the scb_bfar contains the address of the location that generated a bus fault. ? address: bus fault generation location address when the bfarvalid bit of the bfsr subregister is set to 1, this field holds the address of the location that generated the bus fault. notes: 1. when an unaligned access faults, the address in the scb_bfar register is the one requested by the instruction, even if it is not the address of the fault. 2. flags in the bfsr indicate the cause of the fault, and whether the value in the scb_bfar register is valid. see ?bfsr: bus fault status subregister? . 31 30 29 28 27 26 25 24 address 23 22 21 20 19 18 17 16 address 15 14 13 12 11 10 9 8 address 76543210 address
215 sam4cp [datasheet] 43051e?atpl?08/14 12.10 system timer (systick) the processor has a 24-bit system timer, systick, that counts down from the reload value to zero, reloads (wraps to) the value in the syst_rvr on the next clock edge, then counts down on subsequent clocks. when the processor is halted for debugging, the counter does not decrement. the systick counter runs on the processor clock. if this clock signal is stopped for low-power mode, the systick counter stops. ensure that the software uses aligned word accesses to access the systick registers. the systick counter reload and current value are undefined at reset; the correct initialization sequence for the systick counter is: 1. program the reload value. 2. clear the current value. 3. program the control and status register. 12.10.1 system timer (systick) user interface table 12-35. system timer (syst) register mapping offset register name access reset 0xe000e010 systick control and status register syst_csr read/write 0x00000000 0xe000e014 systick reload value register syst_rvr read/write unknown 0xe000e018 systick current value register syst_cvr read/write unknown 0xe000e01c systick calibration value register syst_calib read-only 0x000030d4
216 sam4cp [datasheet] 43051e?atpl?08/14 12.10.1.1 systick control and status register name: syst_csr access: read/write the systick syst_csr register enables the systick features. ? countflag: count flag returns 1 if the timer counted to 0 since the last time this was read. ? clksource: clock source indicates the clock source: 0: external clock. 1: processor clock. ? tickint: systick exception request enable enables a systick exception request: 0: counting down to zero does not assert the systick exception request. 1: counting down to zero asserts the systick exception request. the software can use countflag to determine if systick has ever counted to zero. ? enable: counter enable enables the counter: 0: counter disabled. 1: counter enabled. when enable is set to 1, the counter loads the reload value from the syst_rvr register and then counts down. on reaching 0, it sets the countflag to 1 and optionally asserts the systick depending on the value of tickint. it then loads the reload value again, and begins counting. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? countflag 15 14 13 12 11 10 9 8 ? 76543210 ? ? ? ? ? clksource tickint enable
217 sam4cp [datasheet] 43051e?atpl?08/14 12.10.1.2 systick reload value register name: syst_rvr access: read/write the syst_rvr specifies the start value to load into the syst_cvr. ? reload: syst_cvr load value value to load into the syst_cvr register when the counter is enabled and when it reaches 0. the reload value can be any value in the range 0x00000001-0x00ffffff. a start value of 0 is possible, but has no effect because the systick exception request and countflag are activated when counting from 1 to 0. the reload value is calculated according to its use: for examp le, to generate a multi-shot timer with a period of n processor clock cycles, use a reload value of n-1. if the systick interrupt is required every 100 clock pulses, set reload to 99. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 reload 15 14 13 12 11 10 9 8 reload 76543210 reload
218 sam4cp [datasheet] 43051e?atpl?08/14 12.10.1.3 systick current value register name: syst_cvr access: read/write the systick syst_cvr contains the current value of the systick counter. ? current: systick counter current value reads return the current value of the systick counter. a write of any value clears the field to 0, and also clears the syst_csr.countflag bit to 0. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 current 15 14 13 12 11 10 9 8 current 76543210 current
219 sam4cp [datasheet] 43051e?atpl?08/14 12.10.1.4 systick calibration value register name: syst_calib access: read/write the systick syst_csr register indicates the systick calibration properties. ? noref: no reference clock it indicates whether the device provides a reference clock to the processor: 0: reference clock provided. 1: no reference clock provided. if your device does not provide a reference clock, the syst_csr.clksource bit reads-as-one and ignores writes. ? skew: tenms value verification it indicates whether the tenms value is exact: 0: tenms value is exact. 1: tenms value is inexact, or not given. an inexact tenms value can affect the suitability of systick as a software real time clock. ? tenms: ten milliseconds the reload value for 10 ms (100 hz) timing is subject to system clock skew errors. if the value reads as zero, the calibration value is not known. the tenms field default value is 0x000030d4 (12500 decimal). in order to achieve a 1 ms time base on systick, the tenms field must be programmed to a value corresponding to the proces- sor clock frequency (in khz) divide by 8. for example, for devices running the processor clock at 48 mhz, the tenms field value must be 0x00001770 (48000 khz/8). 31 30 29 28 27 26 25 24 noref skew ? 23 22 21 20 19 18 17 16 tenms 15 14 13 12 11 10 9 8 tenms 76543210 tenms
220 sam4cp [datasheet] 43051e?atpl?08/14 12.11 memory protection unit (mpu) the mpu divides the memory map into a number of regions, and defines the location, size, access permissions, and memory attributes of each region. it supports: ? independent attribute settings for each region. ? overlapping regions. ? export of memory attributes to the system. the memory attributes affect the behavior of memory accesses to the region. the cortex-m4 mpu defines: ? eight separate memory regions, 0-7. ? a background region. when memory regions overlap, a memory access is affected by the attributes of the region with the highest number. for example, the attributes for region 7 take precedence over the attributes of any region that overlaps region 7. the background region has the same memory access attributes as the default memory map, but is accessible from privileged software only. the cortex-m4 mpu memory map is unified. this means that instruction accesses and data accesses have the same region settings. if a program accesses a memory location that is prohibited by the mpu, the processor generates a memory management fault. this causes a fault exception, and might cause the termination of the process in an os environment. in an os environment, the kernel can update the mpu region setting dynamically based on the process to be executed. typically, an embedded os uses the mpu for memory protection. the configuration of mpu regions is based on memory types (see ?memory regions, types and attributes? ). table 12-36 shows the possible mpu region attributes. these include share ability and cache behavior attributes that are not relevant to most microcontroller implementations. see ?mpu configuration for a microcontroller? for guidelines for programming such an implementation. table 12-36. memory attributes summary memory type shareability other attributes description strongly-ordered - - all accesses to strongly-ordered memory occur in program order. all strongly-ordered regions are assumed to be shared. device shared - memory-mapped peripherals that several processors share. non-shared - memory-mapped peripherals that only a single processor uses. normal shared - normal memory that is shared between several processors. non-shared - normal memory that only a single processor uses.
221 sam4cp [datasheet] 43051e?atpl?08/14 12.11.1 mpu access permission attributes this section describes the mpu access permission attributes. the access permission bits (tex, c, b, s, ap, and xn) of the mpu_rasr control the access to the corresponding memory region. if an access is made to an area of memory without the required permissions, then the mpu generates a permission fault. the table below shows the encodings for the tex, c, b, and s access permission bits. notes: 1. the mpu ignores the value of this bit. table 12-38 shows the cache policy for memory attribute encodings with a tex value is in the range 4-7. table 12-37. tex, c, b, and s encoding tex c b s memory type shareability other attributes b000 0 0 x (1) strongly-ordered shareable - 1 x (1) device shareable - 1 0 0 normal not shareable outer and inner write-through. no write allocate. 1 shareable 1 0 normal not shareable outer and inner write-back. no write allocate. 1 shareable b001 0 0 0 normal not shareable - 1 shareable 1 x (1) reserved encoding - 1 0 x (1) implementation defined attributes. - 1 0 normal not shareable outer and inner write-back. write and read allocate. 1 shareable b010 0 0 x (1) device not shareable nonshared device. 1 x (1) reserved encoding - 1x (1) x (1) reserved encoding - b1bb a a 0 normal not shareable - 1 shareable table 12-38. cache policy for memory attribute encoding encoding, aa or bb corresponding cache policy 00 non-cacheable 01 write back, write and read allocate 10 write through, no write allocate 11 write back, no write allocate
222 sam4cp [datasheet] 43051e?atpl?08/14 table 12-39 shows the ap encodings that define the access permissions for privileged and unprivileged software. 12.11.1.1 mpu mismatch when an access violates the mpu permissions, the processor generates a memory management fault, see ?exceptions and interrupts? . the mmfsr indicates the cause of the fault. see ?mmfsr: memory management fault status sub- register? for more information. 12.11.1.2 updating an mpu region to update the attributes for an mpu region, update the mp u_rnr, mpu_rbar and mpu_rasrs. each register can be programed separately, or a multiple-word write can be used to program all of these registers. mpu_rbar and mpu_rasr aliases can be used to program up to four regions simultaneously using an stm instruction. 12.11.1.3 updating an mpu region using separate words simple code to configure one region: ; r1 = region number ; r2 = size/enable ; r3 = attributes ; r4 = address ldr r0,=mpu_rnr ; 0xe000ed98, mpu region number register str r1, [r0, #0x0] ; region number str r4, [r0, #0x4] ; region base address strh r2, [r0, #0x8] ; region size and enable strh r3, [r0, #0xa] ; region attribute disable a region before writing new region settings to the mpu, if the region being changed was previously enabled. for example: ; r1 = region number ; r2 = size/enable ; r3 = attributes ; r4 = address ldr r0,=mpu_rnr ; 0xe000ed98, mpu region number register str r1, [r0, #0x0] ; region number bic r2, r2, #1 ; disable strh r2, [r0, #0x8] ; region size and enable str r4, [r0, #0x4] ; region base address strh r3, [r0, #0xa] ; region attribute orr r2, #1 ; enable strh r2, [r0, #0x8] ; region size and enable table 12-39. ap encoding ap[2:0] privileged permissions unprivileged permissions description 000 no access no access all accesses generate a permission fault 001 rw no access access from privileged software only 010 rw ro writes by unprivileged software generate a permission fault 011 rw rw full access 100 unpredictable unpredictable reserved 101 ro no access reads by privileged software only 110 ro ro read only, by privileged or unprivileged software 111 ro ro read only, by privileged or unprivileged software
223 sam4cp [datasheet] 43051e?atpl?08/14 the software must use memory barrier instructions: ? before the mpu setup, if there might be outstanding memory transfers, such as buffered writes, that might be affected by the change in mpu settings. ? after the mpu setup, if it includes memory transfers that must use the new mpu settings. however, memory barrier instructions are not required if the mpu setup process starts by entering an exception handler, or is followed by an exception return, because the exception entry and exception return mechanisms cause memory barrier behavior. the software does not need any memory barrier instructions during an mpu setup, because it accesses the mpu through the ppb, which is a strongly-ordered memory region. for example, if the user wants all of the memory access behavior to take effect immediately after the programming sequence, a dsb instruction and an isb instruction must be used. a dsb is required after changing mpu settings, such as at the end of a context switch. an isb is required if the code that programs the mpu region or regions is entered using a branch or call. if the programming sequence is entered using a return from exception, or by taking an exception, then an isb is not required. 12.11.1.4 updating an mpu region using multi-word writes the user can program directly using multi-word writes, depending on how the information is divided. consider the following reprogramming: ; r1 = region number ; r2 = address ; r3 = size, attributes in one ldr r0, =mpu_rnr ; 0xe000ed98, mpu region number register str r1, [r0, #0x0] ; region number str r2, [r0, #0x4] ; region base address str r3, [r0, #0x8] ; region attribute, size and enable use an stm instruction to optimize this: ; r1 = region number ; r2 = address ; r3 = size, attributes in one ldr r0, =mpu_rnr ; 0xe000ed98, mpu region number register stm r0, {r1-r3} ; region number, address, attribute, size and enable this can be done in two words for pre-packed information. this means that the mpu_rbar contains the required region number and had the valid bit set to 1. see ?mpu region base address register? . use this when the data is statically packed, for example in a boot loader: ; r1 = address and region number in one ; r2 = size and attributes in one ldr r0, =mpu_rbar ; 0xe000ed9c, mpu region base register str r1, [r0, #0x0] ; region base address and ; region number combined with valid (bit 4) set to 1 str r2, [r0, #0x4] ; region attribute, size and enable use an stm instruction to optimize this: ; r1 = address and region number in one ; r2 = size and attributes in one ldr r0,=mpu_rbar ; 0xe000ed9c, mpu region base register stm r0, {r1-r2} ; region base address, region number and valid bit, ; and region attribute, size and enable
224 sam4cp [datasheet] 43051e?atpl?08/14 12.11.1.5 subregions regions of 256 bytes or more are divided into eight equal-sized subregions. set the corresponding bit in the srd field of the mpu_rasr field to disable a subregion. see ?mpu region attribute and size register? . the least significant bit of srd controls the first subregion, and the most significant bit controls the last subregion. disabling a subregion means another region overlapping the disabled range matches instead. if no other enabled region overlaps the disabled subregion, the mpu issues a fault. regions of 32, 64, and 128 bytes do not support subregions. with regions of these sizes, the srd field must be set to 0x00, otherwise the mpu behavior is unpredictable. 12.11.1.6 example of srd use two regions with the same base address overlap. region 1 is 128 kb, and region 2 is 512 kb. to ensure the attributes from region 1 apply to the first 128 kb region, set the srd field for region 2 to b00000011 to disable the first two subregions, as in figure 12-13 below: figure 12-13. srd use 12.11.1.7 mpu design hints and tips to avoid unexpected behavior, disable the interrupts before updating the attributes of a region that the interrupt handlers might access. ensure the software uses aligned accesses of the correct size to access mpu registers: ? except for the mpu_rasr, it must use aligned word accesses. ? for the mpu_rasr, it can use byte or aligned halfword or word accesses. the processor does not support unaligned accesses to mpu registers. when setting up the mpu, and if the mpu has previously been programmed, disable unused regions to prevent any previous region settings from affecting the new mpu setup. mpu configuration for a microcontroller usually, a microcontroller system has only a single processor and no caches. in such a system, program the mpu as follows: in most microcontroller implementations, the shareability and cache policy attributes do not affect the system behavior. however, using these settings for the mpu regions can make the application code more portable. the values given are for typical situations. in special systems, such as multiprocessor designs or designs with a separate dma engine, the shareability attribute might be important. in these cases, refer to the recommendations of the memory device manufacturer. region 1 region 2, with subregions base address of both regions offset from base address 0 64kb 128kb 192kb 256kb 320kb 384kb 448kb 512kb disabled subregion disabled subregion table 12-40. memory region attributes for a microcontroller memory region tex c b s memory type and attributes flash memory b000 1 0 0 normal memory, non-shareable, write-through internal sram b000 1 0 1 normal memory, shareable, write-through external sram b000 1 1 1 normal memory, shareable, write-back, write-allocate peripherals b000 0 1 1 device memory, shareable
225 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2 memory protection unit (mpu) user interface table 12-41. memory protection unit (mpu) register mapping offset register name access reset 0xe000ed90 mpu type register mpu_type read-only 0x00000800 0xe000ed94 mpu control register mpu_ctrl read/write 0x00000000 0xe000ed98 mpu region number register mpu_rnr read/write 0x00000000 0xe000ed9c mpu region base address register mpu_rbar read/write 0x00000000 0xe000eda0 mpu region attribute and size register mpu_rasr read/write 0x00000000 0xe000eda4 mpu region base address register alias 1 mpu_rbar_a1 read/write 0x00000000 0xe000eda8 mpu region attribute and size register alias 1 mpu_rasr_a1 read/write 0x00000000 0xe000edac mpu region base address register alias 2 mpu_rbar_a2 read/write 0x00000000 0xe000edb0 mpu region attribute and size register alias 2 mpu_rasr_a2 read/write 0x00000000 0xe000edb4 mpu region base address register alias 3 mpu_rbar_a3 read/write 0x00000000 0xe000edb8 mpu region attribute and size register alias 3 mpu_rasr_a3 read/write 0x00000000
226 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.1 mpu type register name: mpu_type access: read-only the mpu_type register indicates whether the mpu is present, and if so, how many regions it supports. ? iregion: instruction region indicates the number of supported mpu instruction regions. always contains 0x00. the mpu memory map is unified and is described by the dregion field. ? dregion: data region indicates the number of supported mpu data regions: 0x08 = eight mpu regions. ? separate: separate instruction indicates support for unified or separate instruction and date memory maps: 0: unified. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 iregion 15 14 13 12 11 10 9 8 dregion 76543210 ? separate
227 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.2 mpu control register name: mpu_ctrl access: read/write the mpu ctrl register enables the mpu, enables the default memory map background region, and enables the use of the mpu when in the hard fault, non-maskable interrupt (nmi), and faultmask escalated handlers. ? privdefena: privileged default memory map enable enables privileged software access to the default memory map: 0: if the mpu is enabled, disables the use of the default memory map. any memory access to a location not covered by any enabled region causes a fault. 1: if the mpu is enabled, enables the use of the default memory map as a background region for privileged software accesses. when enabled, the background region acts as a region number -1. any region that is defined and enabled has priority over this default map. if the mpu is disabled, the processor ignores this bit. ? hfnmiena: hard fault and nmi enable enables the operation of mpu during hard fault, nmi, and faultmask handlers. when the mpu is enabled: 0: mpu is disabled during hard fault, nmi, and faultmask handlers, regardless of the value of the enable bit. 1: the mpu is enabled during hard fault, nmi, and faultmask handlers. when the mpu is disabled, if this bit is set to 1, the behavior is unpredictable. ? enable enables the mpu: 0: mpu disabled. 1: mpu enabled. when enable and privdefena are both set to 1: ? for privileged accesses, the default memory map is as described in ?memory model? . any access by privileged software that does not address an enabled memory region behaves as defined by the default memory map. ? any access by unprivileged software that does not address an enabled memory region causes a memory management fault. xn and strongly-ordered rules always apply to the system control space regardless of the value of the enable bit. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 ? privdefena hfnmiena enable
228 sam4cp [datasheet] 43051e?atpl?08/14 when the enable bit is set to 1, at least one region of the memory map must be enabled for the system to function unless the privdefena bit is set to 1. if the privdefena bit is set to 1 and no regions are enabled, then only privileged software can operate. when the enable bit is set to 0, the system uses the default memory map. this has the same memory attributes as if the mpu is not implemented. the default memory map applies to accesses from both privileged and unprivileged software. when the mpu is enabled, accesses to the system control space and vector table are always permitted. other areas are accessible based on regions and whether privdefena is set to 1. unless hfnmiena is set to 1, the mpu is not enabled when the processor is executing the handler for an exception with priority ?1 or ?2. these priorities are only possible when handling a hard fault or nmi exception, or when faultmask is enabled. setting the hfnmiena bit to 1 enables the mpu when operating with these two priorities.
229 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.3 mpu region number register name: mpu_rnr access: read/write the mpu_rnr selects which memory region is referenced by the mpu_rbar and mpu_rasrs. ? region: mpu region referenced by the mpu_rbar and mpu_rasrs indicates the mpu region referenced by the mpu_rbar and mpu_rasr registers. the mpu supports 8 memory regions, so the permitted values of this field are 0-7. normally, the required region number is written to this register before accessing the mpu_rbar or mpu_rasr. however, the region number can be changed by writing to the mpu_rbar with the valid bit set to 1; see ?mpu region base address regis- ter? . this write updates the value of the region field. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? 76543210 region
230 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.4 mpu region base address register name: mpu_rbar access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr. ? addr: region base address software must ensure that the value written to the addr field aligns with the size of the selected region (size field in the mpu_rasr). if the region size is configured to 4 gb, in the mpu_rasr, there is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for example, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
231 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.5 mpu region attribute and size register name: mpu_rasr access: read/write the mpu_rasr defines the region size and memory attributes of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding sub-region is enabled. 1: corresponding sub-region is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd fiel d as 0x00. ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memory region specified by the mpu_rnr as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. 31 30 29 28 27 26 25 24 ?xn?ap 23 22 21 20 19 18 17 16 ? tex s c b 15 14 13 12 11 10 9 8 srd 76543210 ? size enable
232 sam4cp [datasheet] 43051e?atpl?08/14 note: 1. in the mpu_rbar, see ?mpu region base address register? . ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 - b10011 (19) 1 mb 20 - b11101 (29) 1 gb 30 - b11111 (31) 4 gb b01100 maximum possible size
233 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.6 mpu region base address register alias 1 name: mpu_rbar_a1 access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr. ? addr: region base address software must ensure that the value written to the addr field aligns with the size of the selected region. the value of n depends on the region size. the addr field is bits[31:n] of the mpu_rbar. the region size, as specified by the size field in the mpu_rasr, defines the value of n: n = log2(region size in bytes). if the region size is configured to 4 gb, in the mpu_rasr, there is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for example, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
234 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.7 mpu region attribute and size register alias 1 name: mpu_rasr_a1 access: read/write the mpu_rasr defines the region size and memory attributes of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding subregion is enabled. 1: corresponding subregion is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd fiel d as 0x00. 31 30 29 28 27 26 25 24 ?xn?ap 23 22 21 20 19 18 17 16 ? tex s c b 15 14 13 12 11 10 9 8 srd 76543210 ? size enable
235 sam4cp [datasheet] 43051e?atpl?08/14 ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memory region specified by the mpu_rnr as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. note: 1. in the mpu_rbar; see ?mpu region base address register? . ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 ? b10011 (19) 1 mb 20 ? b11101 (29) 1 gb 30 ? b11111 (31) 4 gb b01100 maximum possible size
236 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.8 mpu region base address register alias 2 name: mpu_rbar_a2 access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr . ? addr: region base address software must ensure that the value written to the addr field aligns with the size of the selected region. the value of n depends on the region size. the addr field is bits[31:n] of the mpu_rbar. the region size, as specified by the size field in the mpu_rasr, defines the value of n: n = log2(region size in bytes). if the region size is configured to 4 gb, in the mpu_rasr, there is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for example, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
237 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.9 mpu region attribute and size register alias 2 name: mpu_rasr_a2 access: read/write the mpu_rasr defines the region size and memory attributes of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding subregion is enabled. 1: corresponding subregion is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd fiel d as 0x00. 31 30 29 28 27 26 25 24 ?xn?ap 23 22 21 20 19 18 17 16 ? tex s c b 15 14 13 12 11 10 9 8 srd 76543210 ? size enable
238 sam4cp [datasheet] 43051e?atpl?08/14 ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memory region specified by the mpu_rnr as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. note: 1. in the mpu_rbar; see ?mpu region base address register? ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 ? b10011 (19) 1 mb 20 ? b11101 (29) 1 gb 30 ? b11111 (31) 4 gb b01100 maximum possible size
239 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.10 mpu region base address register alias 3 name: mpu_rbar_a3 access: read/write the mpu_rbar defines the base address of the mpu region selected by the mpu_rnr, and can update the value of the mpu_rnr. write mpu_rbar with the valid bit set to 1 to change the current region number and update the mpu_rnr. ? addr: region base address software must ensure that the value written to the addr field aligns with the size of the selected region. the value of n depends on the region size. the addr field is bits[31:n] of the mpu_rbar. the region size, as specified by the size field in the mpu_rasr, defines the value of n: n = log2(region size in bytes), if the region size is configured to 4 gb, in the mpu_rasr, there is no valid addr field. in this case, the region occupies the complete memory map, and the base address is 0x00000000. the base address is aligned to the size of the region. for example, a 64 kb region must be aligned on a multiple of 64 kb, for example, at 0x00010000 or 0x00020000. ? valid: mpu region number valid write: 0: mpu_rnr not changed, and the processor updates the base address for the region specified in the mpu_rnr, and ignores the value of the region field. 1: the processor updates the value of the mpu_rnr to the value of the region field, and updates the base address for the region specified in the region field. always reads as zero. ? region: mpu region for the behavior on writes, see the description of the valid field. on reads, returns the current region number, as specified by the mpu_rnr. 31 30 29 28 27 26 25 24 addr 23 22 21 20 19 18 17 16 addr 15 14 13 12 11 10 9 8 addr 76543210 addr valid region
240 sam4cp [datasheet] 43051e?atpl?08/14 12.11.2.11 mpu region attribute and size register alias 3 name: mpu_rasr_a3 access: read/write the mpu_rasr defines the region size and memory attributes of the mpu region specified by the mpu_rnr, and enables that region and any subregions. mpu_rasr is accessible using word or halfword accesses: ? the most significant halfword holds the region attributes. ? the least significant halfword holds the region size, and the region and subregion enable bits. ? xn: instruction access disable 0: instruction fetches enabled. 1: instruction fetches disabled. ? ap: access permission see table 12-39 . ? tex, c, b: memory access attributes see table 12-37 . ? s: shareable see table 12-37 . ? srd: subregion disable for each bit in this field: 0: corresponding subregion is enabled. 1: corresponding subregion is disabled. see ?subregions? for more information. region sizes of 128 bytes and less do not support subregions. when writing the attributes for such a region, write the srd fiel d as 0x00. 31 30 29 28 27 26 25 24 ?xn?ap 23 22 21 20 19 18 17 16 ? tex s c b 15 14 13 12 11 10 9 8 srd 76543210 ? size enable
241 sam4cp [datasheet] 43051e?atpl?08/14 ? size: size of the mpu protection region the minimum permitted value is 3 (b00010). the size field defines the size of the mpu memory region specified by the mpu_rnr as follows: (region size in bytes) = 2 (size+1) the smallest permitted region size is 32b, corresponding to a size value of 4. the table below gives an example of size values, with the corresponding region size and value of n in the mpu_rbar. note: 1. in the mpu_rbar; see ?mpu region base address register? . ? enable: region enable note: for information about access permission, see ?mpu access permission attributes? . size value region size value of n (1) note b00100 (4) 32 b 5 minimum permitted size b01001 (9) 1 kb 10 ? b10011 (19) 1 mb 20 ? b11101 (29) 1 gb 30 ? b11111 (31) 4 gb b01100 maximum possible size
242 sam4cp [datasheet] 43051e?atpl?08/14 12.12 floating point unit (fpu) the cortex-m4f fpu implements the fpv4-sp floating-point extension. the fpu fully supports single-precision add, subtract, multiply, divide, multiply and accumulate, and square root operations. it also provides conversions between fixed-point and floating-point data formats, and floating-point constant instructions. the fpu provides floating-point computation functionality that is compliant with the ansi/ieee std 754-2008, ieee standard for binary floating-point arithmetic, referred to as the ieee 754 standard. the fpu contains 32 single-precision ex tension registers, which can also be ac cessed as 16 doubleword registers for load, store, and move operations. 12.12.1 enabling the fpu the fpu is disabled from reset. it must be enabled before any floating-point instructions can be used. an example code sequence for enabling the fpu in both privileged and user modes is showed below. the processor must be in privileged mode to read from and write to the cpacr. example of enabling the fpu: ; cpacr is located at address 0xe000ed88 ldr.w r0, =0xe000ed88 ; read cpacr ldr r1, [r0] ; set bits 20-23 to enable cp10 and cp11 coprocessors orr r1, r1, #(0xf << 20) ; write back the modified value to the cpacr str r1, [r0]; wait for store to complete dsb ;reset pipeline now the fpu is enabled isb 12.12.2 floating point unit (fpu) user interface table 12-42. floating point unit (fpu) register mapping offset register name access reset 0xe000ed88 coprocessor access control register cpacr read/write 0x00000000 0xe000ef34 floating-point context control register fpccr read/write 0xc0000000 0xe000ef38 floating-point context address register fpcar read/write ? ? floating-point status control register fpscr read/write ? 0xe000e01c floating-point default status control register fpdscr read/write 0x00000000
243 sam4cp [datasheet] 43051e?atpl?08/14 12.12.2.1 coprocessor access control register name: cpacr access: read/write the cpacr specifies the access privileges for coprocessors. ? cp10: access privileges for coprocessor 10 the possible values of each field are: 0: access denied. any attempted access generates a nocp usagefault. 1: privileged access only. an unprivileged access generates a nocp fault. 2: reserved. the result of any access is unpredictable. 3: full access. ? cp11: access privileges for coprocessor 11 the possible values of each field are: 0: access denied. any attempted access generates a nocp usagefault. 1: privileged access only. an unprivileged access generates a nocp fault. 2: reserved. the result of any access is unpredictable. 3: full access. 31 30 29 28 27 26 25 24 ? 23 22 21 20 19 18 17 16 cp11 cp10 ? 15 14 13 12 11 10 9 8 ? 76543210 ?
244 sam4cp [datasheet] 43051e?atpl?08/14 12.12.2.2 floating-point context control register name: fpccr access: read/write the fpccr sets or returns fpu control data. ? aspen: automatic hardware state preservation and restoration enables control bit [2] setting on execution of a floating-point instruction. this results in an automatic hardware state preservation and restoration, for floating-point context, on exception entry and exit. 0: disable control bit [2] setting on execution of a floating-point instruction. 1: enable control bit [2] setting on execution of a floating-point instruction. ? lspen: automatic lazy state preservation 0: disable automatic lazy state preservation for floating-point context. 1: enable automatic lazy state preservation for floating-point context. ? monrdy: debug monitor ready 0: debugmonitor is disabled or the priority did not permit to set mon_pend when the floating-point stack frame was allocated. 1: debugmonitor is enabled and the priority permitted to set mon_pend when the floating-point stack frame was allocated. ? bfrdy: bus fault ready 0: busfault is disabled or the priority did not permit to set the busfault handler to the pending state when the floating-point stack frame was allocated. 1: busfault is enabled and the priority permitted to set the busfault handler to the pending state when the floating-point stac k frame was allocated. ? mmrdy: memory management ready 0: memmanage is disabled or the priority did not permit to set the memmanage handler to the pending state when the floating- point stack frame was allocated. 1: memmanage is enabled and the priority permitted to set the memmanage handler to the pending state when the floating-point stack frame was allocated. ? hfrdy: hard fault ready 0: the priority did not permit to set the hardfault handler to the pending state when the floating-point stack frame was alloca ted. 1: the priority permitted to set the hardfault handler to the pending state when the floating-point stack frame was allocated. 31 30 29 28 27 26 25 24 aspen lspen ? 23 22 21 20 19 18 17 16 ? 15 14 13 12 11 10 9 8 ? monrdy 76543210 ? bfrdy mmrdy hfrdy thread ? user lspact
245 sam4cp [datasheet] 43051e?atpl?08/14 ? thread: thread mode 0: the mode was not the thread mode when the floating-point stack frame was allocated. 1: the mode was the thread mode when the floating-point stack frame was allocated. ? user: user privilege level 0: the privilege level was not user when the floating-point stack frame was allocated. 1: the privilege level was user when the floating-point stack frame was allocated. ? lspact: lazy state preservation active 0: the lazy state preservation is not active. 1: the lazy state preservation is active. the floating-point stack frame has been allocated but saving the state to it has been deferred.
246 sam4cp [datasheet] 43051e?atpl?08/14 12.12.2.3 floating-point context address register name: fpcar access: read/write the fpcar holds the location of the unpopulated floating-point register space allocated on an exception stack frame. ? address: location of unpopulated floating-point register space allocated on an exception stack frame the location of the unpopulated floating-point register space allocated on an exception stack frame. 31 30 29 28 27 26 25 24 address 23 22 21 20 19 18 17 16 address 15 14 13 12 11 10 9 8 address 76543210 address ?
247 sam4cp [datasheet] 43051e?atpl?08/14 12.12.2.4 floating-point status control register name: fpscr access: read/write the fpscr provides all necessary user level control of the floating-point system. ? n: negative condition code flag floating-point comparison operations update this flag. ? z: zero condition code flag floating-point comparison operations update this flag. ? c: carry condition code flag floating-point comparison operations update this flag. ? v: overflow condition code flag floating-point comparison operations update this flag. ? ahp: alternative half-precision control 0: ieee half-precision format selected. 1: alternative half-precision format selected. ? dn: default nan mode control 0: nan operands propagate through to the output of a floating-point operation. 1: any operation involving one or more nans returns the default nan. ? fz: flush-to-zero mode control 0: flush-to-zero mode disabled. the behavior of the floating-point system is fully compliant with the ieee 754 standard. 1: flush-to-zero mode enabled. ? rmode: rounding mode control the encoding of this field is: 0b00: round to nearest (rn) mode. 0b01: round towards plus infinity (rp) mode. 0b10: round towards minus infinity (rm) mode. 0b11: round towards zero (rz) mode. the specified rounding mode is used by almost all floating-point instructions. 31 30 29 28 27 26 25 24 n z c v ? ahp dn fz 23 22 21 20 19 18 17 16 rmode ? 15 14 13 12 11 10 9 8 ? 76543210 idc ? ixc ufc ofc dzc ioc
248 sam4cp [datasheet] 43051e?atpl?08/14 ? idc: input denormal cumulative exception idc is a cumulative exception bit for floating-point exception; see also bits [4:0]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ixc: inexact cumulative exception ixc is a cumulative exception bit for floating-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ufc: underflow cumulative exception ufc is a cumulative exception bit for floating-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ofc: overflow cumulative exception ofc is a cumulative exception bit for floating-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? dzc: division by zero cumulative exception dzc is a cumulative exception bit for floating-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it. ? ioc: invalid operation cumulative exception ioc is a cumulative exception bit for floating-point exception; see also bit [7]. this bit is set to 1 to indicate that the corresponding exception has occurred since 0 was last written to it.
249 sam4cp [datasheet] 43051e?atpl?08/14 12.12.2.5 floating-point default status control register name: fpdscr access: read/write the fpdscr holds the default values for the floating-point status control data. ? ahp: fpscr.ahp default value default value for fpscr.ahp. ? dn: fpscr.dn default value default value for fpscr.dn. ? fz: fpscr.fz default value default value for fpscr.fz. ? rmode: fpscr.rmode default value default value for fpscr.rmode. 31 30 29 28 27 26 25 24 ? ahp dn fz 23 22 21 20 19 18 17 16 rmode ? 15 14 13 12 11 10 9 8 ? 76543210 ?
250 sam4cp [datasheet] 43051e?atpl?08/14 12.13 glossary this glossary describes some of the terms used in technical documents from arm. abort a mechanism that indicates to a processor that the value associated with a memory access is invalid. an abort can be caused by the external or internal memory system as a result of attempting to access invalid instruction or data memory. aligned a data item stored at an address that is divisible by the number of bytes that defines the data size is said to be aligned. aligned words and halfwords have addresses that are divisible by four and two respectively. the terms word-aligned and halfword-aligned therefore stipulate addresses that are divisible by four and two respectively. banked register a register that has multiple physical copies, where the state of the processor determines which copy is used. the stack pointer, sp (r13) is a banked register. base register in instruction descriptions, a register specified by a load or store instruction that is used to hold the base value for the instruction?s address calculation. depending on the instruction and its addressing mode, an offset can be added to or subtracted from the base register value to form the address that is sent to memory. see also ?index register? . big-endian (be) byte ordering scheme in which bytes of decreasing significance in a data word are stored at increasing addresses in memory. see also ?byte-invariant? , ?endianness? , ?little-endian (le)? . big-endian memory memory in which: a byte or halfword at a word-aligned address is the most significant byte or halfword within the word at that address, a byte at a halfword-aligned address is the most significant byte within the halfword at that address. see also ?little-endian memory? . breakpoint a breakpoint is a mechanism provided by debuggers to identify an instruction at which program execution is to be halted. breakpoints are inserted by the programmer to enable inspection of register contents, memory locations, variable values at fixed points in the program execution to test that the program is operating correctly. breakpoints are removed after the program is successfully tested. byte-invariant in a byte-invariant system, the address of each byte of memory remains unchanged when switching between little-endian and big-endian operation. when a data item larger than a byte is loaded from or stored to memory, the bytes making up that data item are arranged into the correct order depending on the endianness of the memory access. an arm byte-invariant implementation also supports unaligned halfword and word memory accesses. it expects multi-word accesses to be word-aligned. condition field a four-bit field in an instruction that specifies a condition under which the instruction can execute.
251 sam4cp [datasheet] 43051e?atpl?08/14 conditional execution if the condition code flags indicate that the corresponding condition is true when the instruction starts executing, it executes normally. otherwise, the instruction does nothing. context the environment that each process operates in for a multitasking operating system. in arm processors, this is limited to mean the physical address range that it can access in memory and the associated memory access permissions. coprocessor a processor that supplements the main processor. cortex-m4 does not support any coprocessors. debugger a debugging system that includes a program, used to detect, locate, and correct software faults, together with custom hardware that supports software debugging. direct memory access (dma) an operation that accesses main memory directly, without the processor performing any accesses to the data concerned. doubleword a 64-bit data item. the contents are taken as being an unsigned integer unless otherwise stated. doubleword-aligned a data item having a memory address that is divisible by eight. endianness byte ordering. the scheme that determines the order that successive bytes of a data word are stored in memory. an aspect of the system?s memory mapping. see also ?little-endian (le)? and ?big-endian (be)? . exception an event that interrupts program execution. when an exception occurs, the processor suspends the normal program flow and starts execution at the address indicated by the corresponding exception vector. the indicated address contains the first instruction of the handler for the exception. an exception can be an interrupt request, a fault, or a software-generated system exception. faults include attempting an invalid memory access, attempting to execute an instruction in an invalid processor state, and attempting to execute an undefined instruction. exception service routine see ?interrupt handler? . exception vector see ?interrupt vector? . flat address mapping a system of organizing memory in which each physical address in the memory space is the same as the corresponding virtual address. halfword a 16-bit data item. illegal instruction an instruction that is architecturally undefined.
252 sam4cp [datasheet] 43051e?atpl?08/14 implementation-defined the behavior is not architecturally defined, but is defined and documented by individual implementations. implementation-specific the behavior is not architecturally defined, and does not have to be documented by individual implementations. used when there are a number of implementation options available and the option chosen does not affect software compatibility. index register in some load and store instruction descriptions, the value of this register is used as an offset to be added to or subtracted from the base register value to form the address that is sent to memory. some addressing modes optionally enable the index register value to be shifted prior to the addition or subtraction. see also ?base register? . instruction cycle count the number of cycles that an instruction occupies the execute stage of the pipeline. interrupt handler a program that control of the processor is passed to when an interrupt occurs. interrupt vector one of a number of fixed addresses in low memory, or in high memory if high vectors are configured, that contains the first instruction of the corresponding interrupt handler. little-endian (le) byte ordering scheme in which bytes of increasing significance in a data word are stored at increasing addresses in memory. see also ?big-endian (be)? , ?byte-invariant? , ?endianness? . little-endian memory memory in which: a byte or halfword at a word-aligned address is the least significant byte or halfword within the word at that address, a byte at a halfword-aligned address is the least significant byte within the halfword at that address. see also ?big-endian memory? . load/store architecture a processor architecture where data-processing operations only operate on register contents, not directly on memory contents. memory protection unit (mpu) hardware that controls access permissions to blocks of memory. an mpu does not perform any address translation. prefetching in pipelined processors, the process of fetching instructions from memory to fill up the pipeline before the preceding instructions have finished executing. prefetching an instruction does not mean that the instruction has to be executed.
253 sam4cp [datasheet] 43051e?atpl?08/14 preserved preserved by writing the same value back that has been previously read from the same field on the same processor. read reads are defined as memory operations that have the semantics of a load. reads include the thumb instructions ldm, ldr, ldrsh, ldrh, ldrsb, ldrb, and pop. region a partition of memory space. reserved a field in a control register or instruction format is reserved if the field is to be defined by the implementation, or produces unpredictable results if the contents of the field are not zero. these fields are reserved for use in future extensions of the architecture or are implementation-specific. all reserved bits not used by the implementation must be written as 0 and read as 0. thread-safe in a multi-tasking environment, thread-safe functions use safeguard mechanisms when accessing shared resources, to ensure correct operation without the risk of shared access conflicts. thumb instruction one or two halfwords that specify an operation for a processor to perform. thumb instructions must be halfword-aligned. unaligned a data item stored at an address that is not divisible by the number of bytes that defines the data size is said to be unaligned. for example, a word stored at an address that is not divisible by four. undefined indicates an instruction that generates an undefined instruction exception. unpredictable one cannot rely on the behavior. unpredictable behavior must not represent security holes. unpredictable behavior must not halt or hang the processor, or any parts of the system. warm reset also known as a core reset. initializes the majority of the processor excluding the debug controller and debug logic. this type of reset is useful if debugging features of a processor. word a 32-bit data item. write writes are defined as operations that have the semantics of a store. writes include the thumb instructions stm, str, strh, strb, and push.
254 sam4cp [datasheet] 43051e?atpl?08/14 13. debug and test features 13.1 description the sam4 series microcontrollers feature a number of complementary debug and test capabilities. the serial wire/jtag debug port (swj-dp) combining a serial wire debug port (sw-dp) and jtag debug (jtag-dp) port is used for standard debugging functions, such as downloading code and single-stepping through programs. it also embeds a serial wire trace. 13.2 associated documentation the sam4cp implements the standard arm coresight ? macrocell. for further detailed coresight information, the following reference documents are available from the arm website: ? cortex-m4/m4f technical reference manual (arm ddi 0439c). ? coresight technology system design guide (arm dgi 0012d). ? coresight components technical reference manual (arm ddi 0314h). ? arm debug interface v5 architecture specification (doc. arm ihi 0031a). ? armv7-m architecture reference manual (arm ddi 0403d). 13.3 embedded characteristics ? dual core debugging with common serial wire debug port (sw-dp) and serial wire jtag debug port (swj-dp) debug access port connected to both cores. ? star topology ahb-ap debug access port implementation with common sw-dp / swj-dp providing higher performance than daisy-chain topology. ? possibility to halt each core on debug event on the other core (hardware). ? possibility to restart each core when the other core has restarted (hardware). ? synchronization and software cross-triggering with debugger. ? instrumentation trace macrocell (itm) on both core for support of printf style debugging. ? mux 2-1 to trace chosen core (limit the number of out put pin). ? single wire viewer or clock mode (4-bit parallel output ports). ? debug access to all memory and registers in the system, including cortex-m4 register bank when the core is running, halted, or held in reset. ? flash patch and breakpoint (fpb) unit for implementing breakpoints and code patches. ? data watchpoint and trace (dwt) unit for implementing watch points, data tracing, and system profiling. ? ieee 1149.1 jtag boundary scan on all digital pins.
255 sam4cp [datasheet] 43051e?atpl?08/14 figure 13-1. debug and test block diagram figure 13-2. dual core debug architecture figure 13-2 illustrates the dual core debug implementation using only one sw-jt ag/sw-dp debug access port. star topology has been used to connect the ahb-ap 0 (core 0) and ahb-ap 1 (core) rather than legacy daisy chaining method. star topology provides higher performance than daisy-chain topology. this core debug architecture is fully supported by debug tools vendors. tst tms tck/swclk tdi jtagsel tdo/traceswo boundary ta p swj-dp reset and test por tdi tdo tms/swdio tck/swclk jtagsel serial wire and jtag debug port (sw-dp / swj-dp) cross-trigering debug event (halt / restart) cortex-m4f core 1 (cm4p1) dap rom tpiu 2 -> 1 dap rom tpiu cortex-m4 core 0 (cm4p0) ahb-ap 1 itm itm trace data ahb-ap 0
256 sam4cp [datasheet] 43051e?atpl?08/14 13.4 cross triggering debut events cross triggering (ct) as shown in figure 13-2 is an atmel module that allows two cores to send and receive debug events to and from each other. this module is used to debug two applications at the same time (one application running on each core). the ct allows core 0 (or 1) to trigger a debug event (halt) to core 1 (or 0) to enter debug mode. the debug event can be sent when the core 0 (or 1) enters debug mode (such as breakpoint) or at run-time. it means that an user application running on core 0 (or 1) can put core 1 (or 0) without entering debug mode. once core 0 (or 1) gets out of debug mode, it releases core 1 (0) from debug mode as well. the cross triggering configuration is located in the special function register in the matrix user interface. 13.5 application examples 13.5.1 debug environment figure 13-3 shows a complete debug environment example. the swj-dp interface is used for standard debugging functions, such as downloading code and single-stepping through the program and viewing core and peripheral registers. figure 13-3. application debug environment example sam4 host debugger pc sam4-based application board swj-dp connector swj-dp emulator/probe
257 sam4cp [datasheet] 43051e?atpl?08/14 13.5.2 test environment figure 13-4 shows a test environment example (jtag boundary scan). test vectors are sent and interpreted by the tester. in this example, the ?board in test? is designed using a number of jtag-compliant devices. these devices can be connected to form a single scan chain. figure 13-4. application test environment example 13.6 debug and test pin description chip 2 chip n chip 1 sam4 sam4-based application board in test jtag connector tester test adaptor jtag probe table 13-1. debug and test signal list signal name function type active level reset/test nrst microcontroller reset input/output low tst test select input swd/jtag tck/swclk test clock/serial wire clock input tdi test data in input tdo/traceswo test data out/trace asynchronous data out output tms/swdio test mode select/serial wire input/output input jtagsel jtag selection input high
258 sam4cp [datasheet] 43051e?atpl?08/14 13.7 functional description 13.7.1 test pin one dedicated pin, tst, is used to define the device operating mode. when this pin is at low level during power-up, the device is in normal operating mode. when at high level, the device is in test mode or ffpi mode. the tst pin integrates a permanent pull-down resistor of about 15 k ?? so that it can be left unconnected for normal operation. note that when setting the tst pin to low or high level at power up, it must remain in the same state during the duration of the whole operation. 13.7.2 debug architecture figure 13-5 shows the debug architecture used in the sam4. the cortex-m4 embeds four functional units for debug: ? swj-dp (serial wire/jtag debug port). ? fpb (flash patch breakpoint). ? dwt (data watchpoint and trace). ? itm (instrumentation trace macrocell). ? tpiu (trace port interface unit). the debug architecture information that follows is mainly dedicated to developers of swj-dp emulators/probes and debugging tool vendors for cortex-m4 based microcontrollers. for further details on swj-dp see the cortex-m4 technical reference manual. figure 13-5. debug architecture 4 watchpoints pc sampler data address sampler data sampler interrupt trace cpu statistics dwt 6 breakpoints fpb software trace 32 channels time stamping itm swd/jtag swj-dp swo trace tpiu
259 sam4cp [datasheet] 43051e?atpl?08/14 13.7.3 serial wire/jtag debug port (swj-dp) the cortex-m4 embeds a swj-dp debug port which is the standard coresight debug port. it combines serial wire debug port (sw-dp), from 2 to 3 pins and jtag debug port (jtag-dp), 5 pins. by default, the jtag debug port is active. if the host debugger wants to switch to the serial wire debug port, it must provide a dedicated jtag sequence on tms/swdio and tck/swclk which disables jtag-dp and enables sw-dp. when the serial wire debug port is active, tdo/traceswo can be used for trace. the asynchronous trace output (traceswo) is multiplexed with tdo. so the asynchronous trace can only be used with sw-dp, not jtag-dp. sw-dp or jtag-dp mode is selected when jtagsel is low. it is not possible to switch directly between swj-dp and jtag boundary scan operations. a chip reset must be performed after jtagsel is changed. 13.7.3.1 sw-dp and jtag-dp selection mechanism debug port selection mechanism is done by sending specific swdiotms sequence. the jtag-dp is selected by default after reset. ? switch from jtag-dp to sw-dp. the sequence is: ? send more than 50 swclktck cycles with swdiotms = 1 ? send the 16-bit sequence on swdiotms = 0111100111100111 (0x79e7 msb first) ? send more than 50 swclktck cycles with swdiotms = 1 ? switch from swd to jtag. the sequence is: ? send more than 50 swclktck cycles with swdiotms = 1 ? send the 16-bit sequence on swdiotms = 0011110011100111 (0x3ce7 msb first) ? send more than 50 swclktck cycles with swdiotms = 1 13.7.4 fpb (flash patch breakpoint) the fpb: ? implements hardware breakpoints. ? ? patches code and data from code space to system space. the fpb unit contains: ? two literal comparators for matching against literal loads from code space, and remapping to a corresponding area in system space. ? six instruction comparators for matching against instruction fetches from code space and remapping to a corresponding area in system space. ? alternatively, comparators can also be configured to generate a breakpoint instruction to the processor core on a match. table 13-2. swj-dp pin list pin name jtag port serial wire debug port tms/swdio tms swdio tck/swclk tck swclk tdi tdi - tdo/traceswo tdo traceswo (optional: trace)
260 sam4cp [datasheet] 43051e?atpl?08/14 13.7.5 dwt (data watchpoint and trace) the dwt contains four comparators which can be configured to generate the following: ? pc sampling packets at set intervals. ? pc or data watchpoint packets. ? watchpoint event to halt core. the dwt contains counters for the items that follow: ? clock cycle (cyccnt). ? folded instructions. ? load store unit (lsu) operations. ? sleep cycles. ? cpi (all instruction cycles except for the first cycle). ? interrupt overhead. 13.7.6 itm (instrumentation trace macrocell) the itm is an application driven trace source that supports printf style debugg ing to trace operating system (os) and application events, and emits diagnostic system information. the itm emits trace information as packets which can be generated by three different sources with several priority levels: ? software trace : software can write directly to itm stimulus registers. this can be done thanks to the ?printf? function. for more information, refer to section 13.7.6.1 ?how to configure the itm? . ? hardware trace : the itm emits packets generated by the dwt. ? time stamping : timestamps are emitted relative to packets. the itm contains a 21-bit counter to generate the timestamp. 13.7.6.1 how to configure the itm the following example describes how to output trace data in asynchronous trace mode. ? configure the tpiu for asynchronous trace mode (refer to section 13.7.6.3 ?how to configure the tpiu? ). ? enable the write accesses into the itm registers by writing ?0xc5acce55? into the lock access register (address: 0xe0000fb0). ? write 0x00010015 into the trace control register: ? enable itm ? enable synchronization packets ? enable swo behavior ? fix the atb id to 1 ? write 0x1 into the trace enable register: ? enable the stimulus port 0 ? write 0x1 into the trace privilege register: ? stimulus port 0 only accessed in privileged mode (clearing a bit in this register will result in the corresponding stimulus port being accessible in user mode) ? write into the stimulus port 0 register: tpiu (trace port interface unit) the tpiu acts as a bridge between the on-chip trace data and the instruction trace macrocell (itm). the tpiu formats and transmits trace data off-chip at frequencies asynchronous to the core.
261 sam4cp [datasheet] 43051e?atpl?08/14 13.7.6.2 asynchronous mode the tpiu is configured in asynchronous mode, trace data are output using the single traceswo pin. the traceswo signal is multiplexed with the tdo signal of the jtag debug port. as a consequence, asynchronous trace mode is only available when the serial wire debug mode is selected since tdo signal is used in jtag debug mode. two encoding formats are available for the single pin output: ? manchester encoded stream. this is the reset value. ? nrz_based uart byte structure. 13.7.6.3 how to configure the tpiu this example only concerns the asynchronous trace mode. ? set the trcena bit to 1 into the debug exception and monitor register (0xe000edfc) to enable the use of trace and debug blocks. ? write 0x2 into the selected pin protocol register. ? select the serial wire output ? nrz ? write 0x100 into the formatter and flush control register. ? set the suitable clock prescaler value into the async clock prescaler register to scale the baud rate of the asynchronous output (this can be done automatically by the debugging tool). 13.7.7 ieee 1149.1 jtag boundary scan ieee 1149.1 jtag boundary scan allows pin-level access independent of the device packaging technology. ieee 1149.1 jtag boundary scan is enabled when tst is tied low, while jtagsel is high and intest7 is tied low during the power-up, and must be kept in this state during the whole boundary scan operation. the sample, extest and bypass functions are implemented. in swd/jtag debug mode, the arm processor responds with a non-jtag chip id that identifies the processor. this is not ieee 1149.1 jtag-compliant. it is not possible to switch directly between jtag boundary scan and swj debug port operations. a chip reset must be performed after jtagsel is changed. a boundary-scan descriptor language (bsdl) file is provided on atmel?s web site to set up the test. 13.7.7.1 jtag boundary-scan register the boundary-scan register (bsr) contains a number of bits which correspond to active pins and associated control signals. each sam4 input/output pin corresponds to a 3-bit register in the bsr. the output bit contains data that can be forced on the pad. the input bit facilitates the observabil ity of data applied to the pad. the control bit selects the direction of the pad. for more information, refer to bdsl files available for the sam4 series.
262 sam4cp [datasheet] 43051e?atpl?08/14 13.7.8 id code register access: read-only ? version[31:28]: product version number set to 0x0. ? part number[27:12]: product part number ? manufacturer identity[11:1] set to 0x01f. ? bit[0] required by ieee std. 1149.1. set to 0x1. 31 30 29 28 27 26 25 24 version part number 23 22 21 20 19 18 17 16 part number 15 14 13 12 11 10 9 8 part number manufacturer identity 76543210 manufacturer identity 1 chip name chip id sam4cp 0x05b34 chip name jtag id code sam4cp 0x05b3_403f
263 sam4cp [datasheet] 43051e?atpl?08/14 14. sam4cp boot program 14.1 description the sam-ba boot program integrates an array of programs permitting download and/or upload into the different memories of the product. 14.2 hardware and software constraints ? sam-ba boot uses the first 4096 bytes of the sram for variables and stacks. the remaining available size can be used for user's code. ? uart0 requirements: none. 14.3 flow diagram the boot program implements the algorithm in figure 14-1 . figure 14-1. boot program algorithm flow diagram the sam-ba boot program uses the internal 12 mhz rc oscillator as source clock for pll. the mck runs from pll divided by 2. the core runs at 48 mhz. 14.4 device initialization initialization follows the steps described below: 1. stack setup 2. setup the embedded flash controller 3. switch on internal 12 mhz rc oscillator 4. configure pllb to run at 48 mhz 5. configure uart0 6. disable watchdog 7. wait for a character on uart0 8. jump to sam-ba monitor (see section 14.5 ?sam-ba monitor? ) table 14-1. pins driven during boot program execution peripheral pin pio line uart0 urxd0 pb4 uart0 utxd0 pb5 device setup character # received from uart0? run sam-ba monitor ye s no
264 sam4cp [datasheet] 43051e?atpl?08/14 14.5 sam-ba monitor the sam-ba boot principle: once the communication interface is identified, to run in an infinite loop waiting for different commands as shown in table 14-2 . ? mode commands: ? normal mode configures sam-ba monitor to send/receive data in binary format ? terminal mode configures sam-ba monitor to send/receive data in ascii format ? write commands: write a byte ( o ), a halfword ( h ) or a word ( w ) to the target ? address : address in hexadecimal ? value : byte, halfword or word to write in hexadecimal ? read commands: read a byte ( o ), a halfword ( h ) or a word ( w ) from the target ? address : address in hexadecimal ? output : the byte, halfword or word read in hexadecimal ? send a file ( s ): send a file to a specified address ? address : address in hexadecimal note: there is a time-out on this command which is reached when the prompt ?>? appears before the end of the command execution. ? receive a file ( r ): receive data into a file from a specified address ? address : address in hexadecimal ? nbofbytes : number of bytes in hexadecimal to receive ? go ( g ): jump to a specified address and execute the code ? address : address to jump in hexadecimal ? get version ( v ): return the sam-ba boot version note: in terminal mode, when the requested command is performed, sam-ba monitor adds the following prompt sequence to its answer: ++'>'. table 14-2. commands available through the sam-ba boot command action argument(s) example n set normal mode no argument n # t set terminal mode no argument t # o write a byte address, value# o 200001,ca# o read a byte address,# o 200001,# h write a half word address, value# h 200002,cafe# h read a half word address,# h 200002,# w write a word address, value# w 200000,cafedeca# w read a word address,# w 200000,# s send a file address,# s 200000,# r receive a file address, nbofbytes# r 200000,1234# g go address# g 200200# v display version no argument v #
265 sam4cp [datasheet] 43051e?atpl?08/14 14.5.1 uart0 serial port communication is performed through the uart0 initialized to 115200 baud, 8, n, 1. the send and receive file commands use the xmodem protocol to communicate. any terminal performing this protocol can be used to send the application file to the target. the size of the binary file to send depends on the sram size embedded in the product. in all cases, the size of the binary file must be lower than the sram size because the xmodem protocol requires some sram memory to work. see section 14.2 ?hardware and software constraints? . 14.5.2 xmodem protocol the supported xmodem protocol is the 128-byte length block. this protocol uses a two-character crc-16 to guarantee detection of a maximum bit error. xmodem protocol with crc is accurate provided both sender and receiver report a successful transmission. each block of the transfer looks like: <255-blk #><--128 data bytes--> where: ? = 01 hex ? = binary number, starts at 01, increments by 1, and wraps 0ffh to 00h (not to 01) ? <255-blk #> = 1?s complement of the blk#. ? = 2 bytes crc16 figure 14-2 shows a transmission using this protocol. figure 14-2. xmodem transfer example host device soh 01 fe data[128] crc crc c ack soh 02 fd data[128] crc crc ack soh 03 fc data[100] crc crc ack eot ack
266 sam4cp [datasheet] 43051e?atpl?08/14 14.5.3 in application programming (iap) feature the iap feature is a function located in rom that can be called by any software application. when called, this function sends the desired flash command to the eefc and waits for the flash to be ready (looping while the frdy bit is not set in the eefc_fsr register). since this function is executed from rom, this allows flash programming (such as sector write) to be done by code running in flash. the iap function entry point is retrieved by reading the nmi vector in rom (0x02000008). this function takes one argument in parameter: the command to be sent to the eefc. this function returns the value of the eefc_fsr register. iap software code example: (unsigned int) (*iap_function)(unsigned long); void main (void){ unsigned long flashsectornum = 200; // unsigned long flash_cmd = 0; unsigned long flash_status = 0; unsigned long efcindex = 0; // 0:eefc0, 1: eefc1 /* initialize the function pointer (retrieve function address from nmi vector) */ iap_function = ((unsigned long) (*)(unsigned long)) 0x02000008; /* send your data to the sector here */ /* build the command to send to eefc */ flash_cmd = (0x5a << 24) | (flashsectornum << 8) | at91c_mc_fcmd_ewp; /* call the iap function with appropriate command */ flash_status = iap_function (efcindex, flash_cmd); }
267 sam4cp [datasheet] 43051e?atpl?08/14 15. reset controller (rstc) 15.1 description the reset controller (rstc), based on power-on reset ce lls, handles all the resets of the system without any external components. it reports which reset occurred last. the reset controller also drives independently or simultaneously the external reset and the peripheral and processor resets. 15.2 embedded characteristics ? management of all system resets, including ? external devices through the nrst pin ? processor reset and coprocessor (second processor) reset ? processor peripheral set reset and coprocessor peripheral set reset ? based on embedded power-on cell ? reset source status ? status of the last reset ? either software reset, user reset, watchdog reset ? external reset signal shaping 15.3 block diagram figure 15-1. reset controller block diagram nrst proc_nreset wd_fault periph_nreset slck reset state manager reset controller rstc_irq nrst manager exter_nreset nrst_out core_backup_reset coproc_nreset coproc_periph_nreset wdrproc user_reset vddcore_nreset
268 sam4cp [datasheet] 43051e?atpl?08/14 15.4 functional description 15.4.1 reset controller overview the reset controller is made up of an nrst manager and a reset state manager. it runs at slow clock and generates the following reset signals: ? proc_nreset: processor reset line. it also resets the watchdog timer ? coproc_nreset: coprocessor (second processor) reset line ? periph_nreset: affects the whole set of embedded peripherals ? coproc_periph_nreset: affects the whole set of embedded peripherals driven by the co- processor ? nrst_out: drives the nrst pin these reset signals are asserted by the reset controller, either on events generated by peripherals, events on nrst pin, or on software action. the reset state manager controls the generation of reset signals and provides a signal to the nrst manager when an assertion of the nrst pin is required. the nrst manager shapes the nrst assertion during a programmable time, thus controlling external device resets. the reset controller mode register (rstc_mr), used to configure the reset controller, is powered with vddbu, so that its configuration is saved as long as vddbu is on. 15.4.2 nrst manager after power-up, nrst is an output during the external reset length (erstl) time period defined in the rstc_mr. when the erstl time has elapsed, the pin behaves as an input and all the system is held in reset if nrst is tied to gnd by an external signal. the nrst manager samples the nrst input pin and drives this pin low when required by the reset state manager. figure 15-2 shows the block diagram of the nrst manager. figure 15-2. nrst manager 15.4.2.1 nrst signal or interrupt the nrst manager samples the nrst pin at slow clock speed. when the line is detected low, a user reset is reported to the reset state manager. however, the nrst manager can be programmed to not trigger a reset when an assertion of nrst occurs. writing a 0 to the ursten in the rstc_mr disables the user reset trigger. the level of the pin nrst can be read at any time in the bit nrstl (nrst level) in the reset controller status register (rstc_sr). as soon as the nrst pin is asserted, the ursts in rstc_sr is set. this bit clears only when rstc_sr is read. the reset controller can also be programmed to generate an interrupt instead of generating a reset. to do so, set the urstien bit in the rstc_mr. external reset timer ursts ursten erstl exter_nreset urstien rstc_mr rstc_mr rstc_mr rstc_sr nrstl nrst_out nrst rstc_irq other interrupt sources user_reset
269 sam4cp [datasheet] 43051e?atpl?08/14 15.4.2.2 nrst external reset control the reset state manager asserts the signal exter_nreset to assert the nrst pin. when this occurs, the ?nrst_out? signal is driven low by the nrst manager for a time programmed by the field erstl in the rstc_mr. this assertion duration, named external reset length, lasts 2 (erstl+1) slow clock cycles. this gives the approximate duration of an assertion between 60 s and 2 seconds. note that erstl at 0 defines a two-cycle duration for the nrst pulse. this feature allows the reset controller to shape the nrst pin level, and thus to guarantee that the nrst line is driven low for a time compliant with potential external devices connected on the system reset. rstc_mr is backed up, making it possible to use the erstl field to shape the system power-up reset for devices requiring a longer startup time than that of the slow clock oscillator. 15.4.3 reset states the reset state manager handles the different reset sources and generates the internal reset signals. it reports the reset status in field rsttyp of the status register (rstc_sr). the update of rstc_sr.rsttyp is performed when the processor reset is released. 15.4.3.1 general reset a general reset occurs when a vddbu power-on-reset is detected, a brownout or a voltage regulation loss is detected by the supply controller. the vddcore_nreset signal is asserted by the supply controller when a general reset occurs. all the reset signals are released and field rstc_sr.rsttyp reports a general reset. as the rstc_mr is reset, the nrst line rises 2 cycles after the vddcore_nreset, as erstl defaults at value 0x0. figure 15-3 shows how the general reset affects the reset signals. figure 15-3. general reset state slck periph_nreset proc_nreset nrst (nrst_out) external reset length = 2 cycles mck processor startup = 2 cycles vddbu_nreset any freq. rsttyp xxx 0x0 = general reset xxx
270 sam4cp [datasheet] 43051e?atpl?08/14 15.4.3.2 backup reset a backup reset occurs when the chip exits from backup mode. while exiting backup mode, the vddcore_nreset signal is asserted by the supply controller. field rstc_sr.rsttyp is updated to report a backup reset. 15.4.3.3 watchdog reset the watchdog reset is entered when a watchdog fault occurs. this reset lasts 3 slow clock cycles. when in watchdog reset, assertion of the reset signals depends on the wdrproc bit in the wdt_mr: ? if wdrproc = 0, the processor reset and the peripheral reset are asserted. the nrst line is also asserted, depending on how field rstc_mr.erstl is programmed. however, the resulting low level on nrst does not result in a user reset state. ? if wdrproc = 1, only the processor reset is asserted. the watchdog timer is reset by the proc_nreset signal. as the watchdog fault always causes a processor reset if wdrsten in the wdt_mr is set, the watchdog timer is always reset after a watchdog reset, and the watchdog is enabled by default and with a period set to a maximum. when bit wdt_mr. wdrsten is reset, the watchdog fault has no impact on the reset controller. figure 15-4. watchdog reset 15.4.3.4 software reset the reset controller offers several commands to assert the different reset signals. these commands are performed by writing the control register (rstc_cr) or coprocessor mode register with the following bits at 1: ? rstc_cr.procrst: writing a 1 to procrst resets the processor and the watchdog timer. ? rstc_cr.perrst: writing a 1 to perrst resets all the embedded peripherals associated to processor whereas the coprocessor peripherals are not reset, including the memory system, and, in particular, the remap command. the peripheral reset is generally used for debug purposes. except for debug purposes, perrst must always be used in conjunction with procrst (perrst and procrst set both at 1 simultaneously). ? rstc_cpmr.cprocen: writing a 0 to cprocen resets the coprocessor only. only if wdrproc = 0 slck periph_nreset proc_nreset wd_fault nrst (nrst_out) external reset length 8 cycles (erstl=2) mck processor startup = 2 cycles any freq. rsttyp any xxx 0x2 = watchdog reset
271 sam4cp [datasheet] 43051e?atpl?08/14 ? rstc_cpmr.cperen: writing a 0 to cperen resets all the embedded peripherals associated to coprocessor whereas the processor peripherals are not reset. ? rstc_cr.extrst: writing a 1 to extrst asserts low the nrst pin during a time defined by the field rstc_mr.erstl. the software reset is entered if at least one of these bits is set by the software. all these commands can be performed independently or simultaneously. the software reset lasts 3 slow clock cycles. the internal reset signals are asserted as soon as the register write is performed. this is detected on the master clock (mck). they are released when the software reset has ended, i.e.; synchronously to slck. if extrst is set, the nrst_out signal is asserted depending on the configuration of the field rstc_mr.erstl. however, the resulting falling edge on nrst does not lead to a user reset. if and only if the procrst bit is set, the reset controller reports the software status in field rstc_sr.rsttyp. other software resets are not reported in rsttyp. as soon as a software operation is detected, the bit srcmp (software reset command in progress) is set in the rstc_sr. srcmp is cleared at the end of the software reset. no other software reset can be performed while the srcmp bit is set, and writing any value in the rstc_cr has no effect. figure 15-5. software reset 15.4.3.5 user reset the user reset is entered when a low level is detected on the nrst pin and the bit ursten in rstc_mr is at 1. the nrst input signal is resynchronized with slck to insure proper behavior of the system. the user reset is entered as soon as a low level is detected on nrst. the processor and coprocessor reset and the peripheral resets are asserted. the user reset ends when nrst rises, after a two-cycle resynchronization time and a 3-cycle processor startup. the processor clock is re-enabled as soon as nrst is confirmed high. slck periph_nreset if perrst=1 proc_nreset if procrst=1 write rstc_cr nrst (nrst_out) if extrst=1 external reset length 8 cycles (erstl=2) mck processor startup = 2 cycles any freq. rsttyp any xxx 0x3 = software reset resynch. 1 cycle srcmp in rstc_sr
272 sam4cp [datasheet] 43051e?atpl?08/14 when the processor reset signal is released, field rstc_sr.rsttyp is loaded with the value 0x4, indicating a user reset. the nrst manager guarantees that the nrst line is asserted for external reset length slow clock cycles, as programmed in field rstc_mr.erstl. however, if nrst does not rise after external reset length because it is driven low externally, the internal reset lines remain asserted until nrst actually rises. figure 15-6. user reset state 15.4.4 reset state priorities the reset state manager manages the priorities among the different reset sources. the resets are listed in order of priority as follows: ? general reset ? backup reset ? watchdog reset ? software reset ? user reset particular cases are listed below: ? when in user reset: ? a watchdog event is impossible because the watchdog timer is being reset by the proc_nreset signal. ? a software reset is impossible, since the processor reset is being activated. ? when in software reset: ? a watchdog event has priority over the current state. ? the nrst has no effect. ? when in watchdog reset: ? the processor reset is active and so a software reset cannot be programmed. ? a user reset cannot be entered. slck periph_nreset proc_nreset nrst nrst (nrst_out) >= external reset length mck processor startup = 2 cycles any freq. resynch. 2 cycles rsttyp any xxx resynch. 2 cycles 0x4 = user reset
273 sam4cp [datasheet] 43051e?atpl?08/14 15.5 reset controller (rstc) user interface table 15-1. register mapping offset register name access reset 0x00 control register rstc_cr write-only ? 0x04 status register rstc_sr read-only 0x0000_0000 0x08 mode register rstc_mr read/write 0x0000 0001 0x0c coprocessor mode register rstc_cpmr read/write 0x0000_0000
274 sam4cp [datasheet] 43051e?atpl?08/14 15.5.1 reset controller control register name: rstc_cr address: 0x400e1400 access: write-only ? procrst: processor reset 0 = no effect. 1 = if key is correct, resets the processor. ? perrst: peripheral reset 0 = no effect. 1 = if key is correct, resets the processor peripherals. ? extrst: external reset 0 = no effect. 1 = if key is correct, asserts the nrst pin. ? key: system reset key 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? extrst perrst ? procrst value name description 0xa5 passwd writing any other value in this field aborts the write operation.
275 sam4cp [datasheet] 43051e?atpl?08/14 15.5.2 reset controller status register name: rstc_sr address: 0x400e1404 access: read-only ? ursts: user reset status a high-to-low transition of the nrst pin sets the ursts bit. this transition is also detected on the mck rising edge. if the us er reset is disabled (ursten = 0 in rstc_mr) and if the interruption is enabled by the urstien bit in the rstc_mr, the ursts bit triggers an interrupt. reading the rstc_sr resets the ursts bit and clears the interrupt. 0 = no high-to-low edge on nrst happened since the last read of rstc_sr. 1 = at least one high-to-low transition of nrst has been detected since the last read of rstc_sr. ? rsttyp: reset type this field reports the cause of the last processor reset. reading this rstc_sr does not reset this field. ? nrstl: nrst pin level this bit registers the nrst pin level sampled on each master clock (mck) rising edge. ? srcmp: software reset command in progress when set, this bit indicates that a software reset command is in progress and that no further software reset should be performe d until the end of the current one. this bit is automatically cleared at the end of the current software reset. 0 = no software command is being performed by the reset controller. the reset controller is ready for a software command. 1 = a software reset command is being performed by the reset controller. the reset controller is busy. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ? ? srcmp nrstl 15 14 13 12 11 10 9 8 ? ? ? ? ? rsttyp 76543210 ??????? ursts value name description 0 general reset first power-up reset 1 backup reset return from backup mode 2 watchdog reset watchdog fault occurred 3 software reset processor reset required by the software 4 user reset nrst pin detected low
276 sam4cp [datasheet] 43051e?atpl?08/14 15.5.3 reset controller mode register name: rstc_mr address: 0x400e1408 access: read/write this register can only be written if the wpen bit is cleared in the system controller write protection mode register (sysc_wpmr). ? ursten: user reset enable 0 = the detection of a low level on the nrst pin does not generate a user reset. 1 = the detection of a low level on the nrst pin triggers a user reset. ? urstien: user reset interrupt enable 0 = usrts bit in rstc_sr at 1 has no effect on rstc_irq. 1 = usrts bit in rstc_sr at 1 asserts rstc_irq if ursten = 0. ? erstl: external reset length this field defines the external reset length. the external reset is asserted during a time of 2 (erstl+1) slow clock cycles. this allows assertion duration to be programmed between 60 s and 2 seconds. note that synchronization cycles must also be con- sidered when calculating the actual reset length as previously described. ? key: write access password 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? erstl 76543210 ? ? ? urstien ? ? ? ursten value name description 0xa5 passwd writing any other value in this field aborts the write operation. always reads as 0.
277 sam4cp [datasheet] 43051e?atpl?08/14 15.5.4 reset controller coprocessor mode register name: rstc_cpmr address: 0x400e140c access: read/write ? cprocen: coprocessor (second processor) enable 0 = if cpkey is correct, resets the coprocessor (power-on default value). 1 = if cpkey is correct, deasserts the reset of the coprocessor. ? cperen: coprocessor peripheral enable 0 = if cpkey is correct, resets the coprocessor peripherals. 1 = if cpkey is correct, deasserts the reset of the coprocessor peripherals. ? cpkey: coprocessor system enable key 31 30 29 28 27 26 25 24 cpkey 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? cperen ? ? ? cprocen value name description 0x5a passwd writing any other value in this field aborts the write operation.
278 sam4cp [datasheet] 43051e?atpl?08/14 16. real-time timer (rtt) 16.1 description the real-time timer (rtt) is built around a 32-bit counter used to count roll-over events of the programmable 16-bit prescaler driven from the 32 khz slow clock source. it generates a periodic interrupt and/or triggers an alarm on a programmed value. the rtt can also be configured to be driven by the 1 hz rtc signal, thus taking advantage of a calibrated 1 hz clock. the slow clock source can be fully disabled to reduce power consumption when only an elapsed seconds count is required. 16.2 embedded characteristics ? 32-bit free-running counter on prescaled slow clock or rtc calibrated 1 hz clock ? 16-bit configurable prescaler ? interrupt on alarm or counter increment 16.3 block diagram figure 16-1. real-time timer s lck rtpres rttinc alms 16-bit divider 32-bit counter almv = crtv rtt_mr rtt_vr rtt_ar rtt_sr rttincien rtt_mr 0 10 almien rtt_in t rtt_mr set set rtt_sr read rtt_sr reset reset rtt_mr reload rtt_alarm rttrst rtt_mr rttrst rtt_mr rttdis 10 rtt_mr rtc1hz rtc 1hz
279 sam4cp [datasheet] 43051e?atpl?08/14 16.4 functional description the programmable 16-bit prescaler value can be configured through the rtpres field in the ?real-time timer mode register? (rtt_mr). configuring the rtpres field value to 0x8000 (default val ue) corresponds to feeding the real-time counter with a 1hz signal (if the slow clock is 32.768 khz). the 32-bit counter can count up to 2 32 seconds, corresponding to more than 136 years, then roll over to 0. bit rttinc in the ?real-time timer status register? (rtt_sr) is set each time there is a prescaler roll-over (see figure 16-2 ). the real-time 32-bit counter can also be supplied by the 1 hz rtc clock. this mode is interesting when the rtc 1hz is calibrated (correction field 0 in rtc_mr) in order to guaranty the synchronism between rtc and rtt counters. setting the rtc1hz bit in the rtt_mr drives the 32-bit rtt counter from the 1hz rtc clock. in this mode, the rtpres field has no effect on 32-bit counter. the prescaler roll-over generates an increment of the real-time timer counter if rtc1hz = 0. otherwise, if rtc1hz = 1, the real-time timer counter is incremented every second. the rttinc bit is set independently from the 32-bit counter increment. the real-time timer can also be used as a free-running timer with a lower time-base. the best accuracy is achieved by writing rtpres to 3 in rtt_mr. programming rtpres to 1 or 2 is forbidden. if the rtt is configured to trigger an interrupt, the interrupt occurs during 2 slow clock cycles after reading rtt_sr. to prevent several executions of the interrupt handler, the interrupt must be disabled in the interrupt handler and re-enabled when the rtt_sr is cleared. the crtv field can be read at any time in the ?real-time timer value register? (rtt_vr). as this value can be updated asynchronously with the master clock, the crtv field must be read twice at the same value to improve accuracy of the returned value. the current value of the counter is compared with the value written in the ?real-time timer alarm register? (rtt_ar). if the counter value matches the alarm, the alms bit in the rtt_sr is set. the rtt_ar is set to its maximum value (0xffff_ffff) after a reset. the alms flag is always a source of the rtt alarm signal that may be used to exit the system from low power modes (see figure 16-1 ) the alarm interrupt must be disabled (almien must be cleared in rtt_mr) when writing a new almv value in the rtt_ar. the rttinc bit can be used to start a periodic interrupt, the period being one second when the rtpres field value=0x8000 and slow clock = 32.768 khz. the rttincien bit must be cleared prior to writing a new rtpres value in the rtt_mr. reading the rtt_sr automatically clears the rttinc and alms bits. writing the rttrst bit in the rtt_mr immediately reloads and restarts the clock divider with the new programmed value. this also resets the 32-bit counter. when not used, the real-time timer can be disabled in o rder to suppress dynamic power consumption in this module. this can be achieved by setting the rttdis bit in the rtt_mr.
280 sam4cp [datasheet] 43051e?atpl?08/14 figure 16-2. rtt counting 16.5 real-time timer (rtt) user interface prescaler almv almv-1 0 almv+1 0 rtpres - 1 crtv read rtt_sr alms (rtt_sr) apb interface slck rttinc (rtt_sr) almv+2 almv+3 ... apb cycle apb cycle table 16-1. register mapping offset register name access reset 0x00 mode register rtt_mr read/write 0x0000_8000 0x04 alarm register rtt_ar read/write 0xffff_ffff 0x08 value register rtt_vr read-only 0x0000_0000 0x0c status register rtt_sr read-only 0x0000_0000
281 sam4cp [datasheet] 43051e?atpl?08/14 16.5.1 real-time timer mode register name: rtt_mr address: 0x400e1430 access: read/write ? rtpres: real-time timer prescaler value defines the number of slck periods required to increment the real-time timer. rtpres is defined as follows: rtpres = 0: the prescaler period is equal to 2 16 * slck periods. rtpres = 1 or 2: forbidden. rtpres 0, 1 or 2: the prescaler period is equal to rtpres * slck periods. note: the rttincien bit must be cleared prior to writing a new rtpres value. ? almien: alarm interrupt enable 0 = the bit alms in rtt_sr has no effect on interrupt. 1 = the bit alms in rtt_sr asserts interrupt. ? rttincien: real-time timer increment interrupt enable 0 = the bit rttinc in rtt_sr has no effect on interrupt. 1 = the bit rttinc in rtt_sr asserts interrupt. ? rttrst: real-time timer restart 0 = no effect. 1 = reloads and restarts the clock divider with the new programmed value. this also resets the 32-bit counter. ? rttdis: real-time timer disable 0 = the real-time timer is enabled. 1 = the real-time timer is disabled (no dynamic power consumption). note: rttdis is write only. ? rtc1hz: real-time clock 1hz clock selection 0 = the rtt 32-bit counter is driven by the 16-bit prescaler roll-over events. 1 = the rtt 32-bit counter is driven by the 1 hz rtc clock. note: rtc1hz is write only. 31 30 29 28 27 26 25 24 ???????r tc1hz 23 22 21 20 19 18 17 16 ? ? ? rttdis ? rttrst rttincien almien 15 14 13 12 11 10 9 8 rtpres 76543210 rtpres
282 sam4cp [datasheet] 43051e?atpl?08/14 16.5.2 real-time timer alarm register name: rtt_ar address: 0x400e1434 access: read/write ? almv: alarm value when the crtv value in rtt_vr equals the almv field, the alms flag is set in rtt_sr. as soon as the alms flag rises, the crtv value equals almv+1 (refer to figure 16-2 ). note: the alarm interrupt must be disabled (almien must be cleared in rtt_mr) when writing a new almv value. 31 30 29 28 27 26 25 24 almv 23 22 21 20 19 18 17 16 almv 15 14 13 12 11 10 9 8 almv 76543210 almv
283 sam4cp [datasheet] 43051e?atpl?08/14 16.5.3 real-time timer value register name: rtt_vr address: 0x400e1438 access: read-only ? crtv: current real-time value returns the current value of the real-time timer. note: as crtv can be updated asynchronously, it must be read twice at the same value. 31 30 29 28 27 26 25 24 crtv 23 22 21 20 19 18 17 16 crtv 15 14 13 12 11 10 9 8 crtv 76543210 crtv
284 sam4cp [datasheet] 43051e?atpl?08/14 16.5.4 real-time timer status register name: rtt_sr address: 0x400e143c access: read-only ? alms: real-time alarm status 0 = the real-time alarm has not occurred since the last read of rtt_sr. 1 = the real-time alarm occurred since the last read of rtt_sr. ? rttinc: real-time timer increment 0 = no prescaler roll-over occurred since the last read of the rtt_sr. 1 = prescaler roll-over occurred since the last read of the rtt_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ? rttinc alms
285 sam4cp [datasheet] 43051e?atpl?08/14 17. real-time clock (rtc) 17.1 description the real-time clock (rtc) peripheral is designed for very low power consumption. for optimal functionality, the rtc requires an accurate external 32.768 khz clock, which can be provided by a crystal oscillator. it combines a complete time-of-day clock with alarm and a two-hundred-year gregorian or persian calendar, complemented by a programmable periodic interrupt. the alarm and calendar registers are accessed by a 32-bit data bus. the time and calendar values are coded in binary-coded decimal (bcd) format. the time format can be 24-hour mode or 12-hour mode with an am/pm indicator. updating time and calendar fields and configuring the alarm fields are performed by a parallel capture on the 32-bit data bus. an entry control is performed to avoid loading registers with incompatible bcd format data or with an incompatible date according to the current month/year/century. a clock divider calibration circuitry enables to compensate crystal oscillator frequency inaccuracy. an rtc output can be programmed to generate several waveforms, including a prescaled clock derived from 32.768 khz 17.2 embedded characteristics ? ultra low power consumption ? full asynchronous design ? gregorian calendar up to 2099 or persian calendar ? programmable periodic interrupt ? safety/security features: ? valid time and date programmation check ? on-the-fly time and date validity check ? crystal oscillator clock calibration ? waveform generation ? tamper timestamping registers ? register write protection 17.3 block diagram figure 17-1. rtc block diagram user interface 32768 divider time slow clock: slck apb date rtc interrupt entry control interrupt control clock calibration rtcout0 wave generator alarm
286 sam4cp [datasheet] 43051e?atpl?08/14 17.4 product dependencies 17.4.1 power management the real-time clock is continuously clocked at 32.768 khz. the power management controller has no effect on rtc behavior. 17.4.2 interrupt rtc interrupt line is connected on one of the internal sources of the interrupt controller. rtc interrupt requires the interrupt controller to be programmed first. 17.5 functional description the rtc provides a full binary-coded decimal (bcd) clock that includes century (19/20), year (with leap years), month, date, day, hours, minutes and seconds. the valid year range is 1900 to 2099 in gregorian mode, a two-hundred-year calendar (or 1300 to 1499 in persian mode). the rtc can operate in 24-hour mode or in 12-hour mode with an am/pm indicator. corrections for leap years are included (all years divisible by 4 being leap years). this is correct up to the year 2099. the rtc can generate configurable waveforms on rtcout0 output. 17.5.1 reference clock the reference clock is slow clock (slck). it can be driven internally or by an external 32.768 khz crystal. during low-power modes of the processor, the oscillator runs and power consumption is critical. the crystal selection has to take into account the current consum ption for power saving and the frequency dri ft due to temperature effect on the circuit for time accuracy. 17.5.2 timing the rtc is updated in real time at one-second intervals in normal mode for the counters of seconds, at one-minute intervals for the counter of minutes and so on. due to the asynchronous operation of the rtc with respect to the rest of the chip, to be certain that the value read in the rtc registers (century, year, month, date, day, hours, minutes, seconds) are valid and stable, it is necessary to read these registers twice. if the data is the same both times, then it is valid. therefore, a minimum of two and a maximum of three accesses are required. 17.5.3 alarm the rtc has five programmable fields: month, date, hours, minutes and seconds. each of these fields can be enabled or disabled to match the alarm condition: ? if all the fields are enabled, an alarm flag is generated (the corresponding flag is asserted and an interrupt generated if enabled) at a given month, date, hour/minute/second. ? if only the ?seconds? field is enabled, then an alarm is generated every minute. depending on the combination of fields enabled, a large number of possibilities are available to the user ranging from minutes to 365/366 days. hour, minute and second matching alarm (secen, minen, houren) can be enabled independently of sec, min, hour fields. note: to change one of the sec, min, hour, date, month fields, it is recommended to disable the field before changing the value and then re-enable it after the change has been made. this requires up to 3 accesses to the rtc_timalr or rtc_calalr. the first access clears the enable corresponding to the field to change (secen, minen, houren, dateen, mthen). if the field is already cleared, this access is not required. the
287 sam4cp [datasheet] 43051e?atpl?08/14 second access performs the change of the value (sec, min, hour, date, month). the third access is required to re-enable the field by writing 1 in secen, minen, houren, dateen, mthen fields. 17.5.4 error checking when programming verification on user interface data is performed when accessing the century, year, month, date, day, hours, minutes, seconds and alarms. a check is performed on illegal bcd entries such as illegal date of the month with regard to the year and century configured. if one of the time fields is not correct, the data is not loaded into the register/counter and a flag is set in the validity register. the user can not reset this flag. it is reset as soon as an acceptable value is programmed. this avoids any further side effects in the hardware. the same procedure is followed for the alarm. the following checks are performed: 1. century (check if it is in range 19 - 20 or 13-14 in persian mode) 2. year (bcd entry check) 3. date (check range 01 - 31) 4. month (check if it is in bcd range 01 - 12, check validity regarding ?date?) 5. day (check range 1 - 7) 6. hour (bcd checks: in 24-hour mode, check range 00 - 23 and check that am/pm flag is not set if rtc is set in 24-hour mode; in 12-hour mode check range 01 - 12) 7. minute (check bcd and range 00 - 59) 8. second (check bcd and range 00 - 59) note: if the 12-hour mode is selected by means of the rtc_mr, a 12-hour value can be programmed and the returned value on rtc_timr will be the corresponding 24-hour value. the entry control checks the value of the am/pm indicator (bit 22 of rtc_timr) to determine the range to be checked. 17.5.5 rtc internal free running counter error checking to improve the reliability and security of the rtc, a permanent check is performed on the internal free running counters to report non-bcd or invalid date/time values. an error is reported by tderr bit in the status register (rtc_sr) if an incorrect value has been detected. the flag can be cleared by programming the tderrclr in the rtc status clear control register (rtc_sccr). anyway the tderr error flag will be set again if the source of the error has not been cleared before clearing the tderr flag. the clearing of the source of such error can be done either by reprogramming a correct value on rtc_calr and/or rtc_timr. the rtc internal free running counters may automatically clear the source of tderr due to their roll-over (i.e. every 10 seconds for seconds[3:0] field in rtc_timr). in this case the tderr is held high until a clear command is asserted by tderrclr bit in rtc_sccr. 17.5.6 updating time/calendar to update any of the time/calendar fields, the user must first stop the rtc by setting the corresponding field in the control register (rtc_cr). bit updtim must be set to update time fields (hour, minute, second) and bit updcal must be set to update calendar fields (century, year, month, date, day). the ackupd bit is automatically set within a second after setting the updtim and/or updcal bit (meaning one second is the maximum duration of the polling or wait for interrupt period). once ackupd is set, it is mandatory to clear this flag by writing the corresponding bit in the rtc_sccr, after which the user can write to the time register, the calendar register, or both. once the update is finished, the user must reset (0) updtim and/or updcal in the rtc_cr. when entering programming mode of the calendar fields, the time fields remain enabled. when entering the programming mode of the time fields, both time and calendar fields are stopped. this is due to the location of the calendar logic circuity (downstream for low-power considerations). it is highly recommended to prepare all the fields to be
288 sam4cp [datasheet] 43051e?atpl?08/14 updated before entering programming mode. in successive update operations, the us er must wait at least one second after resetting the updtim/updcal bit in the rtc_cr before setting these bits a gain. this is done by waiting for the sec flag in the rtc_sr before setting updtim/updcal bit. after resetting updtim/updcal, the sec flag must also be cleared. figure 17-2. update sequence prepare time or calendar fields set updtim and/or updcal bit(s) in rtc_cr read rtc_sr ackupd = 1 ? clear ackupd bit in rtc_sccr update time and/or calendar values in rtc_timr/rtc_calr clear updtim and/or updcal bit in rtc_cr no yes begin end polling or irq (if enabled)
289 sam4cp [datasheet] 43051e?atpl?08/14 17.5.7 rtc accurate clock calibration the crystal oscillator that drives the rtc may not be as accurate as expected mainly due to temperature variation. the rtc is equipped with circuitry able to correct slow clock crystal drift. to compensate for possible temperature variations over time, this accurate clock calibration circuitry can be programmed on-the-fly and also programmed during application manufacturing, in order to correct the crystal frequency accuracy at room temperature (20-25c). the typical clock drift range at room temperature is 20 ppm. in the device operating temperature range, the 32.768 khz crystal oscillator clock inaccuracy can be up to -200 ppm. the rtc clock calibration circuitry allows positive or negative correction in a range of 1.5 ppm to 1950 ppm. after correction, the remaining crystal drift is as follows: ? below 1 ppm, for an initial crystal drift between 1.5 ppm up to 90 ppm ? below 2 ppm, for an initial crystal drift between 90 ppm up to 130 ppm ? below 5 ppm, for an initial crystal drift between 130 ppm up to 200 ppm the calibration circuitry acts by slightly modifying the 1 hz cl ock period from time to time. when the period is modified, depending on the sign of the correction, the 1 hz clock period increases or reduces by around 4 ms. according to the correction, negppm and highppm values configured in the rtc mode register (rtc_mr), the period interval between 2 correction events differs. the inaccuracy of a crystal oscillator at typical room temperature (20 ppm at 20-25 oc) can be compensated if a reference clock/signal is used to measure such inaccuracy. this kind of calibration operation can be set up during the final product manufacturing by means of measurement equipment embedding such a reference clock. the correction of value must be programmed into the rtc mode register (rtc_mr), and this value is kept as long as the circuitry is powered (backup area). removing the backup power supply cancels this calibration. this room temperature calibration can be further processed by means of the networking capability of the target application. to ease the comparison of the inherent crystal accuracy with the reference clock/signal during manufacturing, an internal prescaled 32.768 khz clock derivative signal can be assigned to drive rtc output. to accommodate the measure, several clock frequencies can be selected among 1 hz, 32 hz, 64 hz, 512 hz. in any event, this adjustment does not take into account the temperature variation. the frequency drift (up to -200 ppm) due to temperature variation can be compensated using a reference time if the application can access such a reference. if a reference time cannot be used, a temperature sensor can be placed close to the crystal oscillator in order to get the operating temperature of the crystal oscillator. once obtained, the temperature may be converted using a lookup table (describing the accuracy/temperature curve of the crystal oscillator used) and rtc_mr configured accordingly. the calibration can be perf ormed on-the-fly. this adjustment method is not based on a measurement of the crystal frequency/drift and therefore can be improved by means of the networking capability of the target application. if no crystal frequency adjustment has been done during manufacturing, it is still possible to do it. in the case where a reference time of the day can be obtained through lan/wan network, it is possible to calculate the drift of the application crystal oscillator by comparing the values read on rtc time register (rtc_timr) and programming the highppm and correction fields on rtc_mr according to the difference measured between the reference time and those of rtc_timr. 17.5.8 waveform generation waveforms can be generated by the rtc in order to take advantage of the rtc inherent prescalers while the rtc is the only powered circuitry (low-power mode of operation, backup mode) or in any active modes. going into backup or low power operating modes does not affect the waveform generation outputs. the rtc output (rtcout0) has a source driver selected among 7 possibilities. the first selection choice sticks the associated output at 0 (this is the reset value and it can be used at any time to disable the waveform generation). selection choices 1 to 4 respectively select 1 hz, 32 hz, 64 hz and 512 hz.
290 sam4cp [datasheet] 43051e?atpl?08/14 32 hz or 64 hz can drive, for example, a tn lcd backplane signal while 1 hz can be used to drive a blinking character like ?:? for basic time display (hour, minute) on tn lcds. selection choice 5 provides a toggling signal when the rtc alarm is reached. selection choice 6 provides a copy of the alarm flag, so the associated output is set high (logical 1) when an alarm occurs and immediately cleared when software clears the alarm interrupt source. selection choice 7 provides a 1 hz periodic high pulse of 15 s duration that can be used to drive external devices for power consumption reduction or any other purpose. pio line associated to rtc output is automatically selecting these waveforms as soon as rtc_mr register corresponding fields out0 differ from 0. figure 17-3. waveform generation rtcout0 0 1 hz 32 hz 64 hz 512 hz toggle_alar m flag_alar m pulse 0 1 2 3 4 5 6 7 rtc_mr(out0) flag_alar m alar m m atch event 1 rtc_sccr(alrclr) alar m m atch event 2 rtc_sccr(alrclr) toggle_alar m pulse tperiod tperiod thigh
291 sam4cp [datasheet] 43051e?atpl?08/14 17.5.9 tamper timestamping as soon as a tamper is detected, the tamper counter is incremented and the rtc stores the time of the day, the date and the source of the tamper event in registers located in the backup area. up to two tamper events can be stored. the tamper counter saturates at 15. once this limit is reached, the exact number of tamper occurrence since the last read of stamping registers cannot be known. the first set of timestamping registers (rtc_tstr0, rtc_ tsdr0, rtc_tssr0) cannot be overwritten, so once they have been written all data are stored until the registers are reset.therefore these registers are storing the first tamper occurrence after a read. the second set of timestamping registers (rtc_tstr1, rtc_tsdr1, rtc_tssr1) are overwritten each time a tamper event is detected. this implies that the date and the time data of the first and the second stamping registers may be equal. this occurs when the tamper counter value carried on field tevcnt in rtc_tstr0 equals to 1. thus this second set of registers allows to store the last occurrence of tamper before a read. reading a set of timestamping register requires three accesses, one for the time of the day, one for the date and one for the tamper source. reading the third part (rtc_tssr0/1) of a timestamping registers set clears the whole content of the registers (time, date and tamper source) and makes it available to store a new event. 17.6 real-time clock (rtc) user interface note: if an offset is not listed in the table it must be considered as reserved. table 17-1. register mapping offset register name access reset 0x00 control register rtc_cr read/write 0x0 0x04 mode register rtc_mr read/write 0x0 0x08 time register rtc_timr read/write 0x0 0x0c calendar register rtc_calr read/write 0x01e111220 0x10 time alarm register rtc_timalr read/write 0x0 0x14 calendar alarm register rtc_calalr read/write 0x01010000 0x18 status register rtc_sr read-only 0x0 0x1c status clear command register rtc_sccr write-only ? 0x20 interrupt enable register rtc_ier write-only ? 0x24 interrupt disable register rtc_idr write-only ? 0x28 interrupt mask register rtc_imr read-only 0x0 0x2c valid entry register rtc_ver read-only 0x0 0xb0 timestamp time register 0 rtc_tstr0 read-only 0x0 0xb4 timestamp date register 0 rtc_tsdr0 read-only 0x0 0xb8 timestamp source register 0 rtc_tssr0 read-only 0x0 0xbc timestamp time register 1 rtc_tstr1 read-only 0x0 0xc0 timestamp date register 1 rtc_tsdr1 read-only 0x0 0xc4 timestamp source register 1 rtc_tssr1 read-only 0x0 0xc8 ? 0xe0 reserved register ? ? ? 0xe4 write protection mode register rtc_wpmr read/write 0x00000000 0xe8 ? 0xf8 reserved register ? ? ? 0xfc reserved register ? ? ?
292 sam4cp [datasheet] 43051e?atpl?08/14 17.6.1 rtc control register name: rtc_cr address: 0x400e1460 access: read/write this register can only be written if the wpen bit is cleared in the ?rtc write protection mode register? ? updtim: update request time register 0 = no effect. 1 = stops the rtc time counting. time counting consists of second, minute and hour counters. time counters can be programmed once this bit is set and acknowledged by the bit ackupd of the rtc_sr. ? updcal: update request calendar register 0 = no effect. 1 = stops the rtc calendar counting. calendar counting consists of day, date, month, year and century counters. calendar counters can be programmed once this bit is set and acknowledged by the bit ackupd of the rtc_sr. ? timevsel: time event selection the event that generates the flag timev in rtc_sr depends on the value of timevsel. ? calevsel: calendar event selection the event that generates the flag calev in rtc_sr depends on the value of calevsel. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ? ? calevsel 15 14 13 12 11 10 9 8 ? ? ? ? ? ? timevsel 76543210 ? ? ? ? ? ? updcal updtim value name description 0 minute minute change 1 hour hour change 2 midnight every day at midnight 3 noon every day at noon value name description 0 week week change (every monday at time 00:00:00) 1 month month change (every 01 of each month at time 00:00:00) 2 year year change (every january 1 at time 00:00:00)
293 sam4cp [datasheet] 43051e?atpl?08/14 17.6.2 rtc mode register name: rtc_mr address: 0x400e1464 access: read/write this register can only be written if the wpen bit is cleared in the ?rtc write protection mode register? ? hrmod: 12-/24-hour mode 0 = 24-hour mode is selected. 1 = 12-hour mode is selected. ? persian: persian calendar 0 = gregorian calendar. 1 = persian calendar. ? negppm: negative ppm correction 0 = positive correction (the divider will be slightly higher than 32768). 1 = negative correction (the divider will be slightly lower than 32768). refer to correction and highppm field descriptions. note: negppm must be cleared to correct a crystal slower than 32.768 khz. ? correction: slow clock correction 0 = no correction. 1..127 = the slow clock will be corrected according to the formula given below in highppm description. ? highppm: high ppm correction 0 = lower range ppm correction with accurate correction. 1 = higher range ppm correction with accurate correction. if the absolute value of the correction to be applied is lower than 30 ppm, it is recommended to clear highppm. highppm set to 1 is recommended for 30 ppm correction and above. formula: if highppm = 0, then the clock frequency correction range is from 1.5 ppm up to 98 ppm. the rtc accuracy is less than 1 ppm for a range correction from 1.5 ppm up to 30 ppm. 31 30 29 28 27 26 25 24 ? ? tperiod ? thigh 23 22 21 20 19 18 17 16 ? ? ? ? ? out0 15 14 13 12 11 10 9 8 highppm correction 76543210 ? ? ? negppm ? ? persian hrmod
294 sam4cp [datasheet] 43051e?atpl?08/14 the correction field must be programmed according to the required correction in ppm, the formula is as follows: the value obtained must be rounded to the nearest integer prior to being programmed into correction field. if highppm = 1, then the clock frequency correction range is from 30.5 ppm up to 1950 ppm. the rtc accuracy is less than 1 ppm for a range correction from 30.5 ppm up to 90 ppm. the correction field must be programmed according to the required correction in ppm, the formula is as follows: the value obtained must be rounded to the nearest integer prior to be programmed into correction field. if negppm is set to 1, the ppm correction is negative (used to correct crystal that are faster than the nominal 32.768 khz). ? out0: rtcout0 output source selection ? thigh: high duration of the output pulse ? tperiod: period of the output pulse value name description 0 no_wave no waveform, stuck at ?0? 1 freq1hz 1 hz square wave 2 freq32hz 32 hz square wave 3 freq64hz 64 hz square wave 4 freq512hz 512 hz square wave 5 alarm_toggle output toggles when alarm flag rises 6 alarm_flag output is a copy of the alarm flag 7 prog_pulse duty cycle programmable pulse value name description 0 h_31ms 31.2 ms 1 h_16ms 15.6 ms 2 h_4ms 3.91 ms 3 h_976us 976 s 4 h_488us 488 s 5 h_122us 122 s 6 h_30us 30.5 s 7 h_15us 15.2 s value name description 0 p_1s 1 second 1 p_500ms 500 ms 2 p_250ms 250 ms 3 p_125ms 125 ms correction 3906 20 ppm ? ------------------------ 1 ? = correction 3906 ppm ------------ - 1 ? =
295 sam4cp [datasheet] 43051e?atpl?08/14 17.6.3 rtc time register name: rtc_timr address: 0x400e1468 access: read/write ? sec: current second the range that can be set is 0 - 59 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? min: current minute the range that can be set is 0 - 59 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? hour: current hour the range that can be set is 1 - 12 (bcd) in 12-hour mode or 0 - 23 (bcd) in 24-hour mode. ? ampm: ante meridiem post meridiem indicator this bit is the am/pm indicator in 12-hour mode. 0 = am. 1 = pm. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ampm hour 15 14 13 12 11 10 9 8 ? min 76543210 ? sec
296 sam4cp [datasheet] 43051e?atpl?08/14 17.6.4 rtc calendar register name: rtc_calr address: 0x400e146c access: read/write ? cent: current century the range that can be set is 19 - 20 (gregorian) or 13-14 (persian) (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? year: current year the range that can be set is 00 - 99 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? month: current month the range that can be set is 01 - 12 (bcd). the lowest four bits encode the units. the higher bits encode the tens. ? day: current day in current week the range that can be set is 1 - 7 (bcd). the coding of the number (which number represents which day) is user-defined as it has no effect on the date counter. ? date: current day in current month the range that can be set is 01 - 31 (bcd). the lowest four bits encode the units. the higher bits encode the tens. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ? ? date 23 22 21 20 19 18 17 16 day month 15 14 13 12 11 10 9 8 year 76543210 ? cent
297 sam4cp [datasheet] 43051e?atpl?08/14 17.6.5 rtc time alarm register name: rtc_timalr address: 0x400e1470 access: read/write this register can only be written if the wpen bit is cleared in the ?rtc write protection mode register? note: to change one of the sec, min, hour fields, it is recommended to disable the field before changing the value and then re-enable it after the change has been made. this requires up to three accesses to the rtc_timalr. the first access clears the enable corresponding to the field to change (secen,minen,houren). if the field is already cleared, this access is not required. the second access performs the change of the value (sec, min, hour). the third access is required to re-enable the field by writing 1 in secen, minen, houren fields. ? sec: second alarm this field is the alarm field corresponding to the bcd-coded second counter. ? secen: second alarm enable 0 = the second-matching alarm is disabled. 1 = the second-matching alarm is enabled. ? min: minute alarm this field is the alarm field corresponding to the bcd-coded minute counter. ? minen: minute alarm enable 0 = the minute-matching alarm is disabled. 1 = the minute-matching alarm is enabled. ? hour: hour alarm this field is the alarm field corresponding to the bcd-coded hour counter. ? ampm: am/pm indicator this field is the alarm field corresponding to the bcd-coded hour counter. ? houren: hour alarm enable 0 = the hour-matching alarm is disabled. 1 = the hour-matching alarm is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 houren ampm hour 15 14 13 12 11 10 9 8 minen min 76543210 secen sec
298 sam4cp [datasheet] 43051e?atpl?08/14 17.6.6 rtc calendar alarm register name: rtc_calalr address: 0x400e1474 access: read/write this register can only be written if the wpen bit is cleared in the ?rtc write protection mode register? note: to change one of the date, month fields, it is recommended to disable the field before changing the value and then re-enable it after the change has been made. this requires up to three accesses to the rtc_calalr. the first access clears the enable corresponding to the field to change (dateen,mthen). if the field is already cleared, this access is not required. the second access performs the change of the value (date,month). the third access is required to re- enable the field by writing 1 in dateen, mthen fields. ? month: month alarm this field is the alarm field corresponding to the bcd-coded month counter. ? mthen: month alarm enable 0 = the month-matching alarm is disabled. 1 = the month-matching alarm is enabled. ? date: date alarm this field is the alarm field corresponding to the bcd-coded date counter. ? dateen: date alarm enable 0 = the date-matching alarm is disabled. 1 = the date-matching alarm is enabled. 31 30 29 28 27 26 25 24 dateen ? date 23 22 21 20 19 18 17 16 mthen ? ? month 15 14 13 12 11 10 9 8 ???????? 76543210 ????????
299 sam4cp [datasheet] 43051e?atpl?08/14 17.6.7 rtc status register name: rtc_sr address: 0x400e1478 access: read-only ? ackupd: acknowledge for update ? alarm: alarm flag ? sec: second event ? timev: time event note: the time event is selected in the timevsel field in the rtc_cr and can be any one of the following events: minute change, hour change, noon, midnight (day change). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderr calev timev sec alarm ackupd value name description 0 freerun time and calendar registers cannot be updated. 1 update time and calendar registers can be updated. value name description 0 no_alarmevent no alarm matching condition occurred. 1 alarmevent an alarm matching condition has occurred. value name description 0 no_secevent no second event has occurred since the last clear. 1 secevent at least one second event has occurred since the last clear. value name description 0 no_timevent no time event has occurred since the last clear. 1 timevent at least one time event has occurred since the last clear.
300 sam4cp [datasheet] 43051e?atpl?08/14 ? calev: calendar event note: the calendar event is selected in the calevsel field in the rtc_cr and can be any one of the following events: week change, month change and year change. ? tderr: time and/or date free running error value name description 0 no_calevent no calendar event has occurred since the last clear. 1 calevent at least one calendar event has occurred since the last clear. value name description 0 correct the internal free running counters are carrying valid values since the last read of the rtc_sr. 1 err_timedate the internal free running counters have been corrupted (invalid date or time, non- bcd values) since the last read and/or they are still invalid.
301 sam4cp [datasheet] 43051e?atpl?08/14 17.6.8 rtc status clear command register name: rtc_sccr address: 0x400e147c access: write-only ? ackclr: acknowledge clear 0 = no effect. 1 = clears corresponding status flag in the status register (rtc_sr). ? alrclr: alarm clear 0 = no effect. 1 = clears corresponding status flag in the status register (rtc_sr). ? secclr: second clear 0 = no effect. 1 = clears corresponding status flag in the status register (rtc_sr). ? timclr: time clear 0 = no effect. 1 = clears corresponding status flag in the status register (rtc_sr). ? calclr: calendar clear 0 = no effect. 1 = clears corresponding status flag in the status register (rtc_sr). ? tderrclr: time and/or date free running error clear 0 = no effect. 1 = clears corresponding status flag in the status register (rtc_sr). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderrclr calclr timclr secclr alrclr ackclr
302 sam4cp [datasheet] 43051e?atpl?08/14 17.6.9 rtc interrupt enable register name: rtc_ier address: 0x400e1480 access: write-only ? acken: acknowledge update interrupt enable 0 = no effect. 1 = the acknowledge for update interrupt is enabled. ? alren: alarm interrupt enable 0 = no effect. 1 = the alarm interrupt is enabled. ? secen: second event interrupt enable 0 = no effect. 1 = the second periodic interrupt is enabled. ? timen: time event interrupt enable 0 = no effect. 1 = the selected time event interrupt is enabled. ? calen: calendar event interrupt enable 0 = no effect. 1 = the selected calendar event interrupt is enabled. ? tderren: time and/or date error interrupt enable 0 = no effect. 1 = the time and date error interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderren calen timen secen alren acken
303 sam4cp [datasheet] 43051e?atpl?08/14 17.6.10 rtc interrupt disable register name: rtc_idr address: 0x400e1484 access: write-only ? ackdis: acknowledge update interrupt disable 0 = no effect. 1 = the acknowledge for update interrupt is disabled. ? alrdis: alarm interrupt disable 0 = no effect. 1 = the alarm interrupt is disabled. ? secdis: second event interrupt disable 0 = no effect. 1 = the second periodic interrupt is disabled. ? timdis: time event interrupt disable 0 = no effect. 1 = the selected time event interrupt is disabled. ? caldis: calendar event interrupt disable 0 = no effect. 1 = the selected calendar event interrupt is disabled. ? tderrdis: time and/or date error interrupt disable 0 = no effect. 1 = the time and date error interrupt is disabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tderrdis caldis timdis secdis alrdis ackdis
304 sam4cp [datasheet] 43051e?atpl?08/14 17.6.11 rtc interrupt mask register name: rtc_imr address: 0x400e1488 access: read-only ? ack: acknowledge update interrupt mask 0 = the acknowledge for update interrupt is disabled. 1 = the acknowledge for update interrupt is enabled. ? alr: alarm interrupt mask 0 = the alarm interrupt is disabled. 1 = the alarm interrupt is enabled. ? sec: second event interrupt mask 0 = the second periodic interrupt is disabled. 1 = the second periodic interrupt is enabled. ? tim: time event interrupt mask 0 = the selected time event interrupt is disabled. 1 = the selected time event interrupt is enabled. ? cal: calendar event interrupt mask 0 = the selected calendar event interrupt is disabled. 1 = the selected calendar event interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? cal tim sec alr ack
305 sam4cp [datasheet] 43051e?atpl?08/14 17.6.12 rtc valid entry register name: rtc_ver address: 0x400e148c access: read-only ? nvtim: non-valid time 0 = no invalid data has been detected in rtc_timr (time register). 1 = rtc_timr has contained invalid data since it was last programmed. ? nvcal: non-valid calendar 0 = no invalid data has been detected in rtc_calr (calendar register). 1 = rtc_calr has contained invalid data since it was last programmed. ? nvtimalr: non-valid time alarm 0 = no invalid data has been detected in rtc_timalr (time alarm register). 1 = rtc_timalr has contained invalid data since it was last programmed. ? nvcalalr: non-valid calendar alarm 0 = no invalid data has been detected in rtc_calalr (calendar alarm register). 1 = rtc_calalr has contained invalid data since it was last programmed. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? nvcalalr nvtimalr nvcal nvtim
306 sam4cp [datasheet] 43051e?atpl?08/14 17.6.13 rtc timestamp time register 0 name: rtc_tstr0 address: 0x400e1510 access: read-only ? sec: seconds of the tamper ? min: minutes of the tamper ? hour: hours of the tamper ? ampm: am/pm indicator of the tamper ? tevcnt: tamper events counter each time a tamper event occurs, this counter is incremented. this counter saturates at 15. once this value is reached, it is n o more possible to know the exact number of tamper events. if this field is not null, this implies that at least one tamper event occurs since last register reset and that the values sto red in timestamping registers are valid. ? backup: system mode of the tamper 0 = the state of the system is different from backup mode when the tamper event occurs. 1 = the system is in backup mode when the tamper event occurs. this register is cleared by reading rtc_tssr0. all non-significant bits read zero. 31 30 29 28 27 26 25 24 backup ? ? ? tevcnt 23 22 21 20 19 18 17 16 ? ampm hour 15 14 13 12 11 10 9 8 ? min 76543210 ? sec
307 sam4cp [datasheet] 43051e?atpl?08/14 17.6.14 rtc timestamp time register 1 name: rtc_tstr1 address: 0x400e151c access: read-only ? sec: seconds of the tamper ? min: minutes of the tamper ? hour: hours of the tamper ? ampm: am/pm indicator of the tamper this register is cleared by reading rtc_tssr1. ? backup: system mode of the tamper 0 = the state of the system is different from backup mode when the tamper event occurs. 1 = the system is in backup mode when the tamper event occurs. all non-significant bits read zero. 31 30 29 28 27 26 25 24 backup ? ? ????? 23 22 21 20 19 18 17 16 ? ampm hour 15 14 13 12 11 10 9 8 ? min 76543210 ? sec
308 sam4cp [datasheet] 43051e?atpl?08/14 17.6.15 rtc timestamp date register name: rtc_tsdrx address: 0x400e1514 [0], 0x400e1520 [1] access: read-only ? cent: century of the tamper ? year: year of the tamper ? month: month of the tamper ? day: day of the tamper ? date: date of the tamper the fields contains the date and the source of a tamper occurrence if the tevcnt is not null. this register is cleared by reading rtc_tssr. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ? ? date 23 22 21 20 19 18 17 16 day month 15 14 13 12 11 10 9 8 year 76543210 ? cent
309 sam4cp [datasheet] 43051e?atpl?08/14 17.6.16 rtc timestamp source register name: rtc_tssrx address: 0x400e1518 [0], 0x400e1524 [1] access: read-only ? tsrc: tamper source this field contains the tamper source. it is valid only if the tevcnt is not null. this register is cleared after read and the read access also performs a clear on rtc_tstr and rtc_tsdr. all non-significant bits read zero. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ? tsrc
310 sam4cp [datasheet] 43051e?atpl?08/14 17.6.17 rtc write protection mode register name: rtc_wpmr address: 0x400e1544 access: read/write ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x525443 (?rtc? in ascii). 1: enables the write protection if wpkey corresponds to 0x525443 (?rtc? in ascii). the following registers can be write-protected: ? ?rtc mode register? ? ?rtc time alarm register? ? ?rtc calendar alarm register? ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x525443 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
311 sam4cp [datasheet] 43051e?atpl?08/14 18. watchdog timer (wdt) 18.1 description the watchdog timer (wdt) is used to prevent system lock-up if the software becomes trapped in a deadlock. it features a 12-bit down counter that allows a watchdog period of up to 16 seconds (slow clock around 32 khz). it can generate a general reset or a processor reset only. in addition, it can be stopped while the processor is in debug mode or idle mode. 18.2 embedded characteristics ? 12-bit key-protected programmable counter. ? watchdog clock is independent from processor clock. ? provides reset or interrupt signals to the system. ? counter may be stopped while the processor is in debug state or in idle mode. 18.3 block diagram figure 18-1. watchdog timer block diagram = 0 10 set reset read wdt_sr or reset wdt_fault (to reset controller) set reset wdfien wdt_int wdt_mr slck 1/128 12-bit down counter current value wdd wdt_mr <= wdd wdv wdrstt wdt_mr wdt_cr reload wdunf wderr reload write wdt_mr wdt_mr wdrsten
312 sam4cp [datasheet] 43051e?atpl?08/14 18.4 functional description the watchdog timer is used to prevent system lock-up if the software becomes trapped in a deadlock. it is supplied with vddcore. it restarts with initial values on processor reset. the watchdog is built around a 12-bit down counter, which is loaded with the value defined in the field wdv of the mode register (wdt_mr). the watchdog timer uses the slow clock divided by 128 to establish the maximum watchdog period to be 16 seconds (with a typical slow clock of 32.768 khz). after a processor reset, the value of wdv is 0xfff, corresponding to the maximum value of the counter with the external reset generation enabled (field wdrsten at 1 afte r a backup reset). this means that a default watchdog is running at reset, i.e., at power-up. the user must either disable it (by setting the wddis bit in wdt_mr) if he does not expect to use it or must reprogram it to meet the maximum watchdog period the application requires. if the watchdog is restarted by writing into the control register (wdt_cr), wdt_mr must not be programmed during a period of time of three slow clock periods following the wdt_cr write access. in any case, programming a new value in wdt_mr automatically initiates a restart instruction. wdt_mr can be written only once. only a processor reset resets it. writing wdt_mr reloads the timer with the newly programmed mode parameters. in normal operation, the user reloads the watchdog at regular intervals before the timer underflow occurs, by writing wdt_cr with the bit wdrstt to 1. the watchdog counter is then immediately reloaded from wdt_mr and restarted, and the slow clock 128 divider is reset and restarted. wdt_cr is write-protected. as a result, writing wdt_cr without the correct hard-coded key has no effect. if an underflow does occur, the ?wdt_fault? signal to the reset controller is asserted if the bit wdrsten is set in wdt_mr. moreover, the bit wdunf is set in the status register (wdt_sr). to prevent a software deadlock that cont inuously triggers the watchdog, the rel oad of the watchdog must occur while the watchdog counter is within a window between 0 and wdd, wdd is defined in wdt_mr. any attempt to restart the watchdog while the watchdog counter is between wdv and wdd results in a watchdog error, even if the watchdog is disabled. the bit wderr is updated in wdt_sr and the ?wdt_fault? signal to the reset controller is asserted. note that this feature can be disabled by programming a wdd value greater than or equal to the wdv value. in such a configuration, restarting the watchdog timer is permitted in the whole range [0; wdv] and does not generate an error. this is the default configuration on reset (the wdd and wdv values are equal). the status bits wdunf (watchdog underflow) and wderr (watchdog error) trigger an interrupt, provided the bit wdfien is set in wdt_mr. the signal ?wdt_fault? to the reset controller causes a watchdog reset if the wdrsten bit is set as already explained in the reset controller documentation. in this case, the processor and the watchdog timer are reset, and the wderr and wdunf flags are reset. if a reset is generated or if wdt_sr is read, the status bits are reset, the interrupt is cleared, and the ?wdt_fault? signal t o the reset controller is deasserted. writing wdt_mr reloads and restarts the down counter. while the processor is in debug state or in idle mode, the counter may be stopped depending on the value programmed for the bits wdidlehlt and wddbghlt in wdt_mr.
313 sam4cp [datasheet] 43051e?atpl?08/14 figure 18-2. watchdog behavior 18.5 watchdog timer (wdt) user interface table 18-1. register mapping offset register name access reset 0x00 control register wdt_cr write-only ? 0x04 mode register wdt_mr read/write once 0x3fff_2fff 0x08 status register wdt_sr read-only 0x0000_0000 0 wdv wdd watchdog fault normal behavior watchdog error watchdog underflow fff if wdrsten is 1 if wdrsten is 0 forbidden window permitted window wdt_cr.wdrstt=1
314 sam4cp [datasheet] 43051e?atpl?08/14 18.5.1 watchdog timer control register name: wdt_cr address: 0x400e1450 access: write-only ? wdrstt: watchdog restart 0: no effect. 1: restarts the watchdog if key is written to 0xa5. ? key: password. 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????? wdrstt value name description 0xa5 passwd writing any other value in this field aborts the write operation.
315 sam4cp [datasheet] 43051e?atpl?08/14 18.5.2 watchdog timer mode register name: wdt_mr address: 0x400e1454 access: read/write once notes: 1. the first write access prevents any further modification of the value of this register. read accesses remain possible. 2. the wdd and wdv values must not be modified within three slow clock periods following a restart of the watchdog performed by a write access in the wdt_cr. any modification will cause the watchdog to trigger an end of period earlier than expected. ? wdv: watchdog counter value defines the value loaded in the 12-bit watchdog counter. ? wdfien: watchdog fault interrupt enable 0: a watchdog fault (underflow or error) has no effect on interrupt. 1: a watchdog fault (underflow or error) asserts interrupt. ? wdrsten: watchdog reset enable 0: a watchdog fault (underflow or error) has no effect on the resets. 1: a watchdog fault (underflow or error) triggers a watchdog reset. ? wdrproc: watchdog reset processor 0: if wdrsten is 1, a watchdog fault (underflow or error) activates all resets. 1: if wdrsten is 1, a watchdog fault (underflow or error) activates the processor reset. ? wdd: watchdog delta value defines the permitted range for reloading the watchdog timer. if the watchdog timer value is less than or equal to wdd, writing wdt_cr with wdrstt = 1 restarts the timer. if the watchdog timer value is greater than wdd, writing wdt_cr with wdrstt = 1 causes a watchdog error. ? wddbghlt: watchdog debug halt 0: the watchdog runs when the processor is in debug state. 1: the watchdog stops when the processor is in debug state. 31 30 29 28 27 26 25 24 ? ? wdidlehlt wddbghlt wdd 23 22 21 20 19 18 17 16 wdd 15 14 13 12 11 10 9 8 wddis wdrproc wdrsten wdfien wdv 76543210 wdv
316 sam4cp [datasheet] 43051e?atpl?08/14 ? wdidlehlt: watchdog idle halt 0: the watchdog runs when the system is in idle mode. 1: the watchdog stops when the system is in idle state. ? wddis: watchdog disable 0: enables the watchdog timer. 1: disables the watchdog timer.
317 sam4cp [datasheet] 43051e?atpl?08/14 18.5.3 watchdog timer status register name: wdt_sr address: 0x400e1458 access read-only ? wdunf: watchdog underflow 0: no watchdog underflow occurred since the last read of wdt_sr. 1: at least one watchdog underflow occurred since the last read of wdt_sr. ? wderr: watchdog error 0: no watchdog error occurred since the last read of wdt_sr. 1: at least one watchdog error occurred since the last read of wdt_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ? wderr wdunf
318 sam4cp [datasheet] 43051e?atpl?08/14 19. reinforced safety watchdog timer (rswdt) 19.1 description when two watchdog timers are implemented in a device, the second one, the reinforced safety watchdog timer (rswdt) works in parallel with the watchdog timer (wdt) to reinforce safe watchdog operations. the rswdt can be used to reinforce the safety level provided by the watchdog timer (wdt) in order to prevent system lock-up if the software becomes trapped in a deadlock. the rswdt works in a fully operable mode, independent of the watchdog timer. its clock source is automatically selected from either the slow rc oscillator clock or main rc oscillator divided clock to get an equivalent slow rc oscillator clock. if the watchdog timer clock source (for example the 32 khz crystal oscillator) fails, the system lock-up is no longer monitored by the watchdog timer as the second watchdog timer, rswdt, will perform the monitoring. thus, there is no lack of safety irrespective of the external operating conditions. this rswdt shares the same features as the wdt (i.e. a 12-bit down counter that allows a watchdog period of up to 16 seconds with slow clock at 32.768 khz). it can generate a general reset or a processor reset only. in addition, it can be stopped while the processor is in debug mode or idle mode. 19.2 embedded characteristics ? system safety level reinforced by means of an independent second watchdog timer. ? automatically selected reliable independent clock source other than that of first watchdog timer. ? windowed watchdog. ? 12-bit key-protected programmable counter. ? provides reset or interrupt signals to the system. ? counter may be stopped while the processor is in debug state or in idle mode. 19.3 block diagram figure 19-1. reinforced safety watchdog timer block diagram = 0 10 set reset read rswdt_sr or reset rswdt_fault (to reset controller) (ored with wdt_fault) set reset wdfien rswdt_int (ored with wdt_int) rswdt_mr slow rc clock 1/128 12-bit down counter current value wdd rswdt_mr <= wdd wdv wdrstt rswdt_mr rswdt_cr reload wdunf wderr reload write rswdt_mr rswdt_mr wdrsten main rc clock divider main rc frequency automatic selection [ckgr_mor.moscrcen=0 and (wdt_mr. wddis or supc_mr.xtalsel=1)] 1 0
319 sam4cp [datasheet] 43051e?atpl?08/14 19.4 functional description the rswdt is supplied by vddcore. the rswdt is initialized with default values on processor reset or on power-on sequence and is disabled (its default mode) under such conditions. the rswdt assumes the wdt to be enabled. the main rc oscillator divided clock is selected if the main rc oscillator is already enabled by the application (moscrcen = 1) or if the first watchdog is driven by the slow rc oscillator. the rswdt is built around a 12-bit down counter, which is loaded with a slow clock value other than that of the slow clock in the watchdog timer, defined in the wdv (watchdog counter value) field of the mode register (rswdt_mr). the rswdt uses the slow clock divided by 128 to establish the maximum watchdog period to be 16 seconds (with a typical slow clock of 32.768 khz). after a processor reset, the value of wdv is 0xfff, corresponding to the maximum value of the counter with the external reset generation enabled (rswdt_mr.wdrsten = 1 after a backup reset). this means that a default watchdog is running at reset, i.e., at power-up. if the watchdog is restarted by writing into the control register (rswdt_cr), the rswdt_mr must not be programmed during a period of time of three slow clock periods following the rswdt_cr write access. programming a new value in the rswdt_mr automatically initiates a restart instruction. the rswdt_mr can be written only once. only a processor reset resets it. writing the rswdt_mr reloads the timer with the newly programmed mode parameters. in normal operation, the user reloads the watchdog at regular intervals before the timer underflow occurs, by setting bit rswdt_cr.wdrstt. the watchdog counter is then immediately reloaded from the rswdt_mr and restarted, and the slow clock 128 divider is reset and restarted. the rswdt_cr is write-protected. as a result, writing rswdt_cr without the correct hard-coded key has no effect. if an underflow does occur, the ?wdt_fault? signal to the reset controller is asserted if the bit rswdt_mr.wdrsten is set. moreover, the bit wdunf (watchdog underflow) is set in the status register (rswdt_sr). to prevent a software deadlock that continuously triggers the rswdt, the reload of the rswdt must occur while the watchdog counter is within a window between 0 and the watchdog delta value (wdd). wdd is defined in the rswdt_mr. any attempt to restart the watchdog while the watchdog count er is between the two values wdv and wdd results in a watchdog error, even if the rswdt is disabled. the wderr (watchdog error) bit is updated in the rswdt_sr and the ?wdt_fault? signal to the reset controller is asserted. note that the windowed watchdog feature can be disabled by programming a wdd value greater than or equal to the wdv value. in such a configuration, restarting the rswdt is permitted in the whole range 0 to wdv and does not generate an error. this is the default configuration on reset (the wdd and wdv values are equal). the status bits wdunf and wderr trigger an interrupt, provided the wdfien bit is set in the rswdt_mr. the signal ?wdt_fault? to the reset controller causes a watchdog reset if the wdrsten bit is set as explained in the ?reset controller (rstc)? section of the product datasheet. in that case, the processor and the watchdog timer are reset, and the wdunf and wderr flags are reset. if a reset is generated, or if rswdt_sr is read, the status bits are reset, the interrupt is cleared, and the ?wdt_fault? signal to the reset controller is deasserted. writing the rswdt_mr reloads and restarts the down counter. the rswdt is disabled after any power-on sequence. while the processor is in debug state or in idle mode, the counter may be stopped depending on the value programmed for the wdidlehlt and wddbghlt bits in the rswdt_mr.
320 sam4cp [datasheet] 43051e?atpl?08/14 figure 19-2. watchdog behavior 19.5 reinforced safety watchdog timer (rswdt) user interface 0 wdv wdd rswdt_cr. wdrstt = 1 watchdog fault normal behavior watchdog error watchdog underflow fff if wdrsten is 1 if wdrsten is 0 forbidden window permitted window table 19-1. register mapping offset register name access reset 0x00 control register rswdt_cr write-only ? 0x04 mode register rswdt_mr read/write once 0x3fff_afff 0x08 status register rswdt_sr read-only 0x0000_0000
321 sam4cp [datasheet] 43051e?atpl?08/14 19.5.1 reinforced safety watchdog timer control register name: rswdt_cr address: 0x400e1500 access: write-only ? wdrstt: watchdog restart 0: no effect. 1: restarts the watchdog. ? key: password 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????? wdrstt value name description 0xc4 passwd writing any other value in this field aborts the write operation.
322 sam4cp [datasheet] 43051e?atpl?08/14 19.5.2 reinforced safety watchdog timer mode register name: rswdt_mr address: 0x400e1504 access: read/write once note: the first write access prevents any further modification of the value of this register, read accesses remain possible. note: the wdd and wdv values must not be modified within three slow clock periods following a restart of the watchdog performed by means of a write access in the rswdt_cr, else the watchdog may trigger an end of period earlier than expected. ? wdv: watchdog counter value defines the value loaded in the 12-bit watchdog counter. ? wdfien: watchdog fault interrupt enable 0: a watchdog fault (underflow or error) has no effect on interrupt. 1: a watchdog fault (underflow or error) asserts interrupt. ? wdrsten: watchdog reset enable 0: a watchdog fault (underflow or error) has no effect on the resets. 1: a watchdog fault (underflow or error) triggers a watchdog reset. ? wdrproc: watchdog reset processor 0: if wdrsten is 1, a watchdog fault (underflow or error) activates all resets. 1: if wdrsten is 1, a watchdog fault (underflow or error) activates the processor reset. ? wdd: watchdog delta value defines the permitted range for reloading the watchdog timer. if the watchdog timer value is less than or equal to wdd, writing rswdt_cr with wdrstt = 1 restarts the timer. if the watchdog timer value is greater than wdd, writing rswdt_cr with wdrstt = 1 causes a watchdog error. ? wddbghlt: watchdog debug halt 0: the watchdog runs when the processor is in debug state. 1: the watchdog stops when the processor is in debug state. ? wdidlehlt: watchdog idle halt 0: the watchdog runs when the system is in idle mode. 1: the watchdog stops when the system is in idle state. 31 30 29 28 27 26 25 24 ? ? wdidlehlt wddbghlt wdd 23 22 21 20 19 18 17 16 wdd 15 14 13 12 11 10 9 8 wddis wdrproc wdrsten wdfien wdv 76543210 wdv
323 sam4cp [datasheet] 43051e?atpl?08/14 ? wddis: watchdog disable 0: enables the watchdog timer. 1: disables the watchdog timer.
324 sam4cp [datasheet] 43051e?atpl?08/14 19.5.3 reinforced safety watchdog timer status register name: rswdt_sr address: 0x400e1508 access: read-only ? wdunf: watchdog underflow 0: no watchdog underflow occurred since the last read of rswdt_sr. 1: at least one watchdog underflow occurred since the last read of rswdt_sr. ? wderr: watchdog error 0: no watchdog error occurred since the last read of rswdt_sr. 1: at least one watchdog error occurred since the last read of rswdt_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ? wderr wdunf
325 sam4cp [datasheet] 43051e?atpl?08/14 20. supply controller (supc) 20.1 description the supply controller (supc) controls the supply voltages of the system and manages the backup low-power mode. in this mode, current consumption is reduced to less than 1 microamp (typ) for backup power retention. exit from this mode is possible on multiple wake-up sources. the supc also generates the slow clock by selecting either the low-power rc oscillator or the low-power crystal oscillator. 20.2 embedded characteristics ? manages vddcore and the backup low-power mode by controlling the embedded voltage regulator. ? manages the lcd power supply vddlcd and the backup low-power mode by controlling the embedded lcd voltage regulator. ? a supply monitor detection on vddio or a brownout detection on vddcore triggers a system reset. ? a supply monitor detection on vddbu_sw triggers a system reset. ? generates the slow clock slck, by selecting either the 32 khz low-power rc oscillator or the 32 khz low power crystal oscillator. ? supports multiple wake-up sources, for exit from backup low-power mode. ? force wake-up pin, with programmable debouncing. ? up to 16 wake-up inputs (including tamper inputs), with programmable debouncing. ? real-time clock alarm. ? real-time timer alarm. ? supply monitor detection on vddio, with programmable scan period and voltage threshold.
326 sam4cp [datasheet] 43051e?atpl?08/14 20.3 block diagram figure 20-1. supply controller block diagram supply monitoring vddbu vddout shdn vddlcd (in/out) core voltage regulator vroff onreg vddin lcd voltage regulator lcdmode - off (lcdoff), - active (lcdon_extvr), - hi-z (lcdon_extvr) lcdvrout vddlcd adjust backup mode used/unused automatic power switch note: tmpx signals and wkupx signals are multiplexed on the same pins (ex. tmp0/wkup0, tmp1/wkup10, etc.). this generates a wake-up event only, a tamper event only or a wake-up and a tamper event. rstc module vddcore_nreset (system reset signal) core_backup_reset vddbu_sw reset enable disable power-on-reset vddcore brownout detector vddcore programmable supply monitor vddio zero-power power-on-reset vddbu_sw threshold enable sampling period reset enable interrupt enable wake-up enable vddio xtalsel slck (slow clock) porcore_out bodcore_out smio_out porbusw_out smen smien smrsten smsmpl smth bupporen bodrsten boddis wake-up & tamper inputs timstpm3dis timstpm2dis timstpm1dis timestamp disable rtc module wkupx x:1..15 wkupdbc wkupen[1..15] programmable debouncer wake-up tmp1/2/3 lpdbc lpdbcen[1..3] programmable lp debouncer tamper wkup0 wkupdbc wkupen0 programmable debouncer wake-up tmp0 lpdbc lpdbcen0 programmable lp debouncer tamper fwup fwupdbc fwupen programmable debouncer wake-up clear on tamper event (8/16) lpdbcclr lpdbdisclr1 lpdbdisclr2 lpdbdisclr3 general purpose backup registers x8 x8 supplied by vddcore supplied by vddbu_sw supplied by vddio supplied by vddin supply controller rtt module rtten wake-up rtcen wake-up rc osc 32khz oscbypass xtal osc 32khz slow clock control i/o pin referred to vddbu i/o pin referred to vddio
327 sam4cp [datasheet] 43051e?atpl?08/14 20.4 supply controller functional description 20.4.1 supply controller overview the device can be divided into two power supply areas: ? the backup vddbu_sw power supply that includes the supply controller, a part of the reset controller, the slow clock switch, the general-purpose backup registers, the supply monitor and the clock which includes the real-time timer and the real-time clock ? the core power supply that includes the other part of the reset controller, the brownout detector, the processor, the sram memory, the flash memory and the peripherals the supply controller (supc) controls the core power supply. the supc intervenes when the vddbu_sw power supply rises (when the system is starting) or when the backup low-power mode is entered. the supc also integrates the slow clock generator which is based on a 32 khz crystal oscillator and an embedded 32 khz rc oscillator. the slow clock defaults to the rc oscillator, but the software can enable the crystal oscillator and select it as the slow clock source. the supply controller and the vddbu_sw power supply have a reset circuitry based on a zero-power power-on reset cell. the zero-power power-on reset allows the supc to start properly as soon as the vddbu_sw voltage becomes valid. at start-up of the system, once the backup voltage vddbu_sw is valid and the embedded 32 khz rc oscillator is stabilized, the supc starts up the core voltage regulator and ties the shdn pin to vddbu.once the vddcore voltage is valid, it releases the system reset signal (vddcore_nreset) to the rstc. the rstc module then releases the sub-system 0 reset signals (proc_nreset and periph_nreset). note that the sub-system 1 remains in reset after power-up. once the system has started, the user can program a supply monitor and/or a brownout detector. if a powerfail condition occurs on either vddio or on vddcore power supplies, the supc asserts the system reset signal (vddcore_nreset). this signal is released when the powerfail condition is cleared. when the backup low-power mode is entered, the supc sequ entially asserts the system reset signal and disables the voltage regulator, in order to maintain only the vddbu_sw power supply. current consumption is reduced to less than one microamp for the backup part retention. exit from this mode is possible on multiple wake-up sources including an event on the fwup pin or wkupx pins, or a clock alarm. to exit this mode, the supc operates in the same way as system start-up, in particular, the supc starts by enabling the core voltage regulator and the shdn pin. 20.4.2 slow clock generator the supply controller embeds a slow clock generator that is supplied with the vddbu_sw power supply. as soon as the vddbu_sw is supplied, both the crystal oscillator and the embedded rc oscillator are powered up, but only the embedded rc oscillator is enabled. this allows the slow clock to be valid in a short time (about 100 s). the user can select the crystal oscillator to be the source of the slow clock, as it provides a more accurate frequency. the command is executed by writing the supply controller control register (supc_cr) with the xtalsel bit at 1, resulting in the following sequence: 1. the crystal oscillator is enabled. 2. a number of slow rc oscillator clock periods is counted to cover the start-up time of the crystal oscillator (refer to the electrical characteristics for information on 32 khz crystal oscillator start-up time). 3. the slow clock is switched to the output of the crystal oscillator. 4. the rc oscillator is disabled to save power. the switching time may vary depending on the slow rc oscillator clock frequency range. the switch of the slow clock source is glitch-free. the oscsel bit of the supply controller status register (supc_sr) indicates when the switch sequence is finished. coming back on the rc oscillator is only possible by shutting down the vddbu_sw power supply. if the user does not need the crystal oscillator, the xin32 and xout32 pins should be left unconnected. the user can also set the crystal oscillator in bypass mode instead of connecting a crystal. in this case, the user has to provide the external clock signal on xin32. the input characteristics of the xin32 pin are given in the electrical
328 sam4cp [datasheet] 43051e?atpl?08/14 characteristics section. in order to set the bypass mode, the oscbypass bit of the supply controller mode register (supc_mr) must be set at 1. 20.4.3 core voltage regulator control/backup low-power mode the supply controller can be used to control the embedded voltage regulator. the voltage regulator automatically adapts its quiescent current depending on the required load current. more information can be found in the electrical characteristics section. the user can switch off the voltage regulator, and thus put the device in backup mode, by writing supc_cr with the vroff bit at 1. this asserts the system reset signal after the write resynchronization time which lasts two slow clock cycles (worst case). once the system reset signal is asserted, the processor and the peripherals are stopped one slow clock cycle before shutting down the core voltage regulator and pulling the shdn pin to ground. when the user does not use the internal voltage regulator and wants to supply vddcore by an external supply, it is possible to disable the voltage regulator. this is done through onreg bit in supc_mr. 20.4.4 lcd voltage regulator control the supply controller can be used to select the power supply source of the lcd voltage regulator. this selection is done by the lcdmode field in supc_mr. after a backup reset, the lcdmode field is at 0x0. no power supply source is selected and the slcd controller reset signal is asserted. the status of the lcd controller reset is given by the lcds field in supc_ sr. ? if lcdmode is written to 0x2 while it is at 0x0, after the write resynchronization time (about 2 slow clock cycles), the external power supply source is selected, then after one slow clock cycle, the slcdc reset signal is released. ? if lcdmode is written to 0x0 while it is at 0x2, after the write resynchronization time (about 2 slow clock cycles), the slcdc reset signal is asserted, then after one slow clock cycle, the external power supply source is deselected. ? if lcdmode is written to 0x3 while it is at 0x0, after the write resynchronization time (about 2 slow clock cycles), the internal power supply source is selected and the embedded regulator is turned on, then after 15 slow clock cycles, the slcdc reset signal is released. ? if lcdmode is written to 0x0 while it is at 0x3, after the write resynchronization time (about 2 slow clock cycles), the slcdc reset signal, then after one slow clock cycle, the internal power supply source is deselected. there are several restrictions concerning the write of the lcdmode field: ? the user must check that the previous power supply selection is done before writing lcdmode again. to do that, the user must check that the lcds flag has the correct value. if lcdmode is written to 0x0, the lcds flag is reset at 0. if lcdmode is written to 0x0, the lcds flag is set at 1. ? writing lcdmode to 0x2 while it is at 0x3 or writing lcdmode to 0x3 while it is at 0x2 is forbidden and has no effect. ? before writing lcdmode to 0x2, the user must ensure that the external power supply is ready and supplies the vddlcd pin. ? before writing lcdmode to 0x3, the user must ensure that the external power supply does not supply the vddlcd pin. to use the lcd controller to maintain display in backup mode, all configuration registers must be kept when backup mode entered. 20.4.5 using backup battery/automatic power switch the power switch is able to automatically select one power source among vddbu and vddio. as soon as vddio is present (higher than 1.9v), it supplies the backup area of the device (vddbu_sw = vddio) even if the voltage of vddbu is higher than vddio. if not, the backup area is supplied by the vddbu voltage source (vddbu_sw = vddbu). for more information about power supply schematics, refer to the section on power considerations.
329 sam4cp [datasheet] 43051e?atpl?08/14 20.4.6 supply monitor the supply controller embeds a supply monitor located in the vddbu_sw power domain and which monitors vddio power supply. the supply monitor can be used to prevent the processor from falling into an unpredictable state if the main power supply drops below a certain level. the threshold of the supply monitor is programmable. it can be selected from 1.9v to 3.4v by steps of 100 mv. this threshold is programmed in the smth field of the supply controller supply monitor mode register (supc_smmr). the supply monitor can also be enabled during one slow clock period on every one of either 32, 256 or 2048 slow clock periods, depending on what the user selects. this can be configured by programming the smsmpl field in supc_smmr. enabling the supply monitor for such reduced times divides the typical supply monitor power consumption by factors of 32, 256 or 2048,respectively, if the user does not need a continuous monitoring of the vddio power supply. a supply monitor detection can either generate a system reset (vddcore_nreset signal is asserted) or a system wake-up. generating a system reset when a supply monitor detection occurs is enabled by writing the smrsten bit to 1 in supc_smmr. waking up the system when a supply monitor detection occurs can be enabled by writing the smen bit to 1 in the supply controller wake-up mode register (supc_wumr). the supply controller provides two status bits in the supply controller status register for the supply monitor which determines whether the last wake-up was due to the supply monitor: ? the smos bit provides real-time information, updated at each measurement cycle or updated at each slow clock cycle, if the measurement is continuous. ? the sms bit provides saved information and shows a supply monitor detection has occurred since the last read of supc_sr. the sms bit can generate an interrupt if the smien bit is set to 1 in supc_smmr. figure 20-2. supply monitor status bit and associated interrupt supply monitor on 3.3 v 0 v threshold sms and supc interrupt read supc_sr periodic sampling continuous sampling (smsmpl = 1)
330 sam4cp [datasheet] 43051e?atpl?08/14 20.4.7 backup power supply reset 20.4.7.1 raising the backup power supply as soon as the backup voltage vddbu_sw rises, the 32 khz rc oscillator is powered up and the zero-power power-on reset cell maintains its output low as long as vddbu_sw has not reached its target voltage. during this time, the supply controller is entirely reset. when the vddbu_sw voltage becomes valid and zero-power power-on reset signal is released, a counter is started for five slow clock cycles, which is the time required for the 32 khz rc oscillator to stabilize . after this time, the shdn pin is asserted high and the core voltage regulator is enabled. the core power supply rises and the brownout detector provides the core regulator status as soon as the core voltage vddcore is valid. the system reset signal is then released to the reset controller after the core voltage status has been confirmed as being valid for at least one slow clock cycle. figure 20-3. raising the vddbu_sw power supply 20.4.7.2 shdn output pin the shdn pin is designed to drive the enable pin of an external voltage regulator. this pin is controlled by the vroff bit in supc_cr. when the device goes into backup mode (vroff written to 1), the shdn pin is asserted low. upon a wake-up event, the shdn pin is released (vddbu level). zero-power power-on reset cell output 22 - 42 khz rc oscillator output fast rc oscillator output backup power supply shdn core regulator status from bod core (vddcore_nreset) nrst (no ext. drive assumed) processor reset (core 0 only) note: after processor reset rising, the core starts fetching instructions from flash at 4 mhz. peripheral reset 7 x slow clock cycles 3 x slow clock cycles 2 x slow clock cycles 6.5 x slow clock cycles t on voltage regulator zero-power por core power supply rstc.erstl (5 for startup slow rc + 2 for synchro.) default = 2 system reset
331 sam4cp [datasheet] 43051e?atpl?08/14 20.4.8 system reset the supply controller manages the system reset signal (vddcore_nreset) to the reset controller, as described in section 20.4.7 ?backup power supply reset? . the system reset signal is normally asserted before shutting down the core power supply and released as soon as the core power supply is correctly regulated. there are two additional sources which can be programmed to activate the system reset signal: ? a supply monitor detection ? a brownout detection 20.4.8.1 supply monitor reset the supply monitor is capable of generating a reset of the system. this can be enabled by setting the smrsten bit in supc_smmr. if smrsten is set and if a supply monitor detection occurs, the system reset signal is immediately activated for a minimum of 1 slow clock cycle. 20.4.8.2 brownout detector reset the brownout detector provides the core voltage status signal (bodcore_out) to the supc which indicates that the voltage regulation is operating as programmed. if this signal is lost for longer than 1 slow clock period while the voltage regulator is enabled, the supply controller can assert system reset signal. this feature is enabled by writing bodrsten (brownout detector reset enable) to 1 in supc_mr. if bodrsten is set and the voltage regulation is lost (output voltage of the regulator too low), the system reset signal is asserted for a minimum of 1 slow clock cycle and then released if the core voltage status has been reactivated. the bodrsts bit is set in supc_sr so that the user knows the source of the last reset. the system reset signal remains active as long as the core voltage status signal (bodcore_out) indicates a powerfail condition. 20.4.8.3 power-on-reset on vddbu_sw the power-on-reset monitors vddbu_sw. it is active by default and monitors voltage at start up but also during power down. it can be deactivated by software through supc_mr. if vddbu_sw goes below the threshold voltage, the entire chip is reset. note that due to the automatic power switch, vddbu_sw can be either vddio or vddbu.
332 sam4cp [datasheet] 43051e?atpl?08/14 20.4.9 wake-up sources the wake-up events allow the device to exit backup mode. when a wake-up event is detected, the supply controller performs a sequence which automatically reenables the core power supply. figure 20-4. wake-up sources wkup15 wkupt15 wkupen1 wkupen0 & lpdbcen0=0 debouncer slck wkupdbc wkups rtcen rtc alarm smen supply monitor core supply restart wkupis0 wkupis1 wkupis15 wkupt0 wkupt1 wkup0/tmp0 wkup1 rtten rtt alarm debouncer rtcout0 lpdbc debouncer lpdbc rtcout0 lpdbcs0 lpdbcen1 wkupt10 lpdbcen0 wkupt0 low/high level detect low/high level detect low/high level detect low/high level detect low/high level detect low/high level detect low/high level detect fwup debouncer fwupdbc fwup fwupen falling edge detector slck wkup14/tmp2 or or wkup10/tmp1 wkup15/tmp3 lpdbcen2 wkupt14 lpdbcen3 wkupt15 or enable enable enable wkupen0 lpdbcs1 wkupen10 lpdbcs2 wkupen14 lpdbcs3 wkupen15 wkupen15 & lpdbcen3=0
333 sam4cp [datasheet] 43051e?atpl?08/14 20.4.9.1 force wake-up the fwup pin is enabled as a wake-up source by writing the fwupen bit to 1 in supc_wumr. the fwupdbc field in the same register then selects the debouncing period, which can be selected between 3, 32, 512, 4,096 or 32,768 slow clock cycles, corresponding to about 100 s, about 1 ms, about 16 ms, about 128 ms and about 1 second, respectively (for a typical slow clock frequency of 32 khz). programmi ng fwupdbc to 0x0 selects an immediate wake-up, i.e., the fwup must be low during at least one slow clock period to wake up the system. if the fwup pin is asserted for a time longer than the debouncing period, a system wake-up is started and the fwup bit in supc_sr is set and remains high until the register is read. 20.4.9.2 wake-up inputs the wake-up inputs wkupx can be programmed to perform a system wake-up. each input can be enabled by writing to 1 the corresponding bit, wkupenx, in the wake-up inputs register (supc_wuir). the wake-up level can be selected with the corresponding polarity bit, wkupplx, also located in supc_wuir. all the resulting signals are wired-ored to trigger a debounce counter, which can be programmed with the wkupdbc field in supc_wumr. the wkupdbc field can select a debouncing period of 3, 32, 512, 4,096 or 32,768 slow clock cycles. this corresponds respectively to about 100 s, about 1 ms, about 16 ms, about 128 ms and about 1 second (for a typical slow clock frequency of 32 khz). programming wkupdbc to 0x0 selects an immediate wake-up, i.e., an enabled wkup pin must be active according to its polarity during a minimum of one slow clock period to wake up the core power supply. if an enabled wkupx pin is asserted for a time longer than the debouncing period, a system wake-up is started and the signals, wkupx as shown in figure 20-4 , are latched in supc_sr. this allows the user to identify the source of the wake-up, however, if a new wake-up condition occurs, the primary information is lost. no new wake-up can be detected since the primary wake-up condition has disappeared. 20.4.9.3 low-power debouncer inputs (tamper detection pins) low-power debouncer inputs are dedicated to tamper detection. if the tamper sensor is biased through a resistor and constantly driven by the power supply, this leads to power c onsumption as long as the tamper detection switch is in its active state. to prevent power consumption when the switch is in active state, the tamper sensor circuitry can be intermittently powered, thus, a specific waveform must be generated. it is possible to generate a waveform (on pin rtcout0) in all modes (including backup mode). refer to the rtc section for waveform generation. two separate debouncers are embedded, one for wkup0/tmp0 input and a shared one for wkup10/tmp1, wkup14/tmp2, wkup15/tmp3 inputs. see figure 20-4 . the wkup0/tmp0 and/or wkup10/tmp1, wkup14/tmp2, wkup15/tmp3 inputs can be programmed to perform a system wake-up with a debouncing done by rtcout0. this can be enabled by setting lpdbcen0/1/2/3 bit in the ?supply controller wake-up mode register? (supc_wumr). these inputs can be also used when vddcore is powered to get tamper detection function with a low-power debounce function and to raise an interrupt. this mode of operation requires the rtc output (rtcout0) to be configured to generate a duty cycle programmable pulse (i.e. out0 = 0x7 in rtc_mr) in order to create the sampling points of both debouncers. the sampling point is the falling edge of the rtcout0 waveform. figure 20-5 shows an example of an applicat ion where two tamper switches are used. rtcout0 powers the external pull-up used by the tampers.
334 sam4cp [datasheet] 43051e?atpl?08/14 figure 20-5. low-power debouncer (push-to-make switch, pull-up resistors) figure 20-6. low-power debouncer (push-to-break switch, pull-down resistors) the debouncing period duration is configurable.the period is identical for all debouncers (i.e., the duration cannot be adjusted separately for each debouncer). the number of successive identical samples to wake up the system can be configured from 2 up to 8 in the lpdbc field of supc_wumr. the period of time between two samples can be configured by programming the tperiod field in the rtc_mr. power parameters can be adjusted by modifying the period of time in the thigh field in rtc_mr. the wake-up polarity of the inputs can be independently configured by writing wkupt0/wkupt10/wkupt14 /wkupt15 fields in supc_wumr. in order to determine which wake-up/tamper pin triggers the system wake-up, a status flag is associated for each low- power debouncer. these flags can be read in the supc_sr. a debounce event (tamper detection) can perform an immediate clear (0 delay) on first half the general-purpose backup registers (gpbr). the lpdbcclr bit must be set in section 20.6.5 ?supply controller mode register? and it is possible to individually disable the clear capability for tmp1/tmp2/tmp3 by writing a 1 in the corresponding bit distmpclr1/2/3. note that it is not mandatory to use the rtcout0 pin when using the wkup0/wkup10/wkup14/wkup15 pins as tampering inputs (tmp0/tmp1/tmp2/tmp3) in any mode. u sing rtcout0 pin provides a ?sampling mode? to further reduce the power consumption of the tamper detection circuitry. if rtcout0 is not used, the rtc must be configured to create an internal sampling point for the debouncer logic. the period of time between two samples can be configured by programming the tperiod field in the rtc_mr. mcu wkup0/tmp0 wkupx/tmpx rtcout0 pull-up resistor pull-up resistor gnd gnd gnd mcu wkup0/tmp0 wkupx/tmpx rtcout0 pull-down resistors gnd gnd gnd
335 sam4cp [datasheet] 43051e?atpl?08/14 figure 20-7 shows how to use wkupx/tmpx without rtcout0 pin. figure 20-7. using wkup/tmp pins without rtcout pins 20.4.9.4 clock alarms the rtc and the rtt alarms generates a system wake-up. this can be enabled by writing respectively, the bits rtcen and rtten to 1 in supc_wumr. the supply controller does not provide any status as the information is available in the user interface of either the real- time timer or the real-time clock. 20.4.9.5 supply monitor detection the supply monitor generates a system wake-up when configured as a wake-up source. see section 20.4.6 ?supply monitor? . 20.5 register write protection to prevent any single software error from corrupting supc behavior, certain registers in the address space can be write- protected by setting the wpen bit in the ?system controller write protection mode register? (sysc_wpmr). the following registers can be write-protected: ? rstc mode register ? rtt mode register ? rtt alarm register ? rtc control register ? rtc mode register ? rtc time alarm register ? rtc calendar alarm register ? general purpose backup registers ? supply controller control register ? supply controller supply monitor mode register ? supply controller mode register ? supply controller wake-up mode register ? supply controller wake-up inputs register mcu wkup0/tmp0 wkupx/tmpx rtcout0 vdd pull-up resistor pull-up resistor gnd gnd gnd
336 sam4cp [datasheet] 43051e?atpl?08/14 20.6 supply controller (supc) user interface the user interface of the supply controller is part of the system controller user interface. 20.6.1 system controller (sysc) user interface 20.6.2 supply controller (supc) user interface table 20-1. system controller peripheral offsets offset system controller peripheral name 0x00 - 0x0c reset controller rstc 0x10 - 0x2c supply controller supc 0x30 - 0x3c real time timer rtt 0x50 - 0x5c watchdog timer wdt 0x60 - 0x8c real time clock rtc 0x90 - 0xdc general purpose backup register gpbr 0xe0 reserved 0xe4 write protection mode register sysc_wpmr 0xe8 - 0xf8 reserved 0xfc reserved 0x100 - 0x10c reinforced safety watchdog timer rswdt 0x110 - 0x124 time stamping register rtc table 20-2. register mapping offset register name access reset 0x00 supply controller control register supc_cr write-only n/a 0x04 supply controller supply monitor mode register supc_smmr read/write 0x0000_0000 0x08 supply controller mode register supc_mr read/write 0x0000_da00 0x0c supply controller wake-up mode register supc_wumr read/write 0x0000_0000 0x10 supply controller wake-up inputs register supc_wuir read/write 0x0000_0000 0x14 supply controller status register supc_sr read-only 0x0000_0000 0x18 reserved - - - 0xfc reserved - - -
337 sam4cp [datasheet] 43051e?atpl?08/14 20.6.3 supply controller control register name: supc_cr address: 0x400e1410 access: write-only ? vroff: voltage regulator off 0 (no_effect) = no effect. 1 (stop_vreg) = if key is correct, asserts the system reset signal and stops the voltage regulator. ? xtalsel: crystal oscillator select 0 (no_effect) = no effect. 1 (crystal_sel) = if key is correct, switches the slow clock on the crystal oscillator output. ? key: password 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? xtalsel vroff ? ? value name description 0xa5 passwd writing any other value in this field aborts the write operation.
338 sam4cp [datasheet] 43051e?atpl?08/14 20.6.4 supply controller supply monitor mode register name: supc_smmr address: 0x400e1414 access: read/write ? smth: supply monitor threshold selects the threshold voltage of the supply monitor. refer to the electrical characteristics for voltage values. ? smsmpl: supply monitor sampling period ? smrsten: supply monitor reset enable 0 (not_enable) = the system reset signal is not affected when a supply monitor detection occurs. 1 (enable) = the system reset signal is asserted when a supply monitor detection occurs. ? smien: supply monitor interrupt enable 0 (not_enable) = the supc interrupt signal is not affected when a supply monitor detection occurs. 1 (enable) = the supc interrupt signal is asserted when a supply monitor detection occurs. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? smien smrsten ? smsmpl 76543210 ? ? ? ? smth value name description 0x0 smd supply monitor disabled 0x1 csm continuous supply monitor 0x2 32slck supply monitor enabled one slck period every 32 slck periods 0x3 256slck supply monitor enabled one slck period every 256 slck periods 0x4 2048slck supply monitor enabled one slck period every 2,048 slck periods
339 sam4cp [datasheet] 43051e?atpl?08/14 20.6.5 supply controller mode register name: supc_mr address: 0x400e1418 access: read/write ? lcdvrout: lcd voltage regulator output adjusts the output voltage of the lcd voltage regulator. refer to the electrical characteristics for voltage values. ? lcdmode: lcd controller mode of operation ? bodrsten: brownout detector reset enable 0 (not_enable) = the system reset signal is not affected when a brownout detection occurs. 1 (enable) = the system reset signal is asserted when a brownout detection occurs. ? boddis: brownout detector disable 0 (enable) = the core brownout detector is enabled. 1 (disable) = the core brownout detector is disabled. ? onreg: voltage regulator enable 0 (onreg_unused) = internal voltage regulator is not used (external power supply is used). 1 (onreg_used) = internal voltage regulator is used. ? bupporen: backup area power-on reset enable 0 (buppor_disable) = disables the backup por. 1 (buppor_enable) = enables the backup por. note: the value written in bupporen is effective when buppors has the same value in ?supply controller status register? . 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 ???oscbypass???? 15 14 13 12 11 10 9 8 bupporen onreg boddis bodrsten ???? 76543210 ? ? lcdmode lcdvrout value name description 0x0 lcdoff the internal supply source and the external supply source are both deselected.(off mode). 0x2 lcdon_extvr the external supply source for lcd (vddlcd) is selected (the lcd voltage regulator is in hi-z mode). 0x3 lcdon_invr the internal supply source for lcd (the lcd voltage regulator) is selected (active mode).
340 sam4cp [datasheet] 43051e?atpl?08/14 ? oscbypass: oscillator bypass 0 (no_effect) = no effect. clock selection depends on xtalsel value. 1 (bypass) = the 32 khz crystal oscillator is selected and put in bypass mode. ? key: password key value name description 0xa5 passwd writing any other value in this field aborts the write operation.
341 sam4cp [datasheet] 43051e?atpl?08/14 20.6.6 supply controller wake-up mode register name: supc_wumr address: 0x400e141c access: read/write ? fwupen: force wake-up enable 0 (not_enable) = the force wake-up pin has no wake-up effect. 1 (enable) = the force wake-up pin low forces a system wake-up. ? smen: supply monitor wake-up enable 0 (not_enable) = the supply monitor detection has no wake-up effect. 1 (enable) = the supply monitor detection forces a system wake-up. ? rtten: real-time timer wake-up enable 0 (not_enable) = the rtt alarm signal has no wake-up effect. 1 (enable) = the rtt alarm signal forces a system wake-up. ? rtcen: real-time clock wake-up enable 0 (not_enable) = the rtc alarm signal has no wake-up effect. 1 (enable) = the rtc alarm signal forces a system wake-up. ? lpdbcen0: low-power debouncer enable wkup0/tmp0 0 (not_enable) = the wkup0/tmp0 input pin is not connected to the low-power debouncer. 1 (enable) = the wkup0/tmp0 input pin is connected to the low-power debouncer and can force a system wake-up. ? lpdbcen1: low-power debouncer enable wkup10/tmp1 0 (not_enable) = the wkup10/tmp1 input pin is not connected to the low-power debouncer. 1 (enable) = the wkup10/tmp1 input pin is connected to the low-power debouncer and can force a system wake-up. ? lpdbcclr: low-power debouncer clear 0 (not_enable) = a low-power debounce event does not create an immediate clear on the first half of gpbr registers. 1 (enable) = a low-power debounce event on wkup0/tmp0 or wkup10/14/15/tmp1/2/3 (if distmpclr1/2/3 is cleared) generates an immediate clear on the first half of gpbr registers. 31 30 29 28 27 26 25 24 ? diststmp3 diststmp2 diststmp1 ? distmpclr3 distmpclr2 distmpclr1 23 22 21 20 19 18 17 16 ? ? lpdbcen3 lpdbcen2 ? lpdbc 15 14 13 12 11 10 9 8 ? wkupdbc ? fwupdbc 76543210 lpdbcclr lpdbcen1 lpdbcen0 ? rtcen rtten smen fwupen
342 sam4cp [datasheet] 43051e?atpl?08/14 ? fwupdbc: force wake-up debouncer period ? wkupdbc: wake-up inputs debouncer period ? lpdbc: low-power debouncer period ? lpdbcen2: low-power debouncer enable wkup14/tmp2 0 (not_enable) = the wkup14/tmp2 input pin is not connected to the low-power debouncer. 1 (enable) = the wkup14/tmp2 input pin is connected to the low-power debouncer and can force a system wake-up. ? lpdbcen3: low-power debouncer enable wkup15/tmp3 0 (not_enable) = the wkup15/tmp3 input pin is not connected to the low-power debouncer. 1 (enable) = the wkup15/tmp3 input pin is connected to the low-power debouncer and can force a system wake-up. ? distmpclr1: disable gpbr clear command from wkup10/tmp1 pin 0 (enable) = the wkup10/tmp1 input pin can clear the gpbr (if lpdbcclr is enabled) when tamper is detected. 1 (disable) = the wkup10/tmp1 input pin has no effect on the gpbr value (no clear on tamper detection). value name description 0 immediate immediate, no debouncing, detected active at least on one slow clock edge 1 3_slck fwup shall be low for at least 3 slck periods 2 32_slck fwup shall be low for at least 32 slck periods 3 512_slck fwup shall be low for at least 512 slck periods 4 4096_slck fwup shall be low for at least 4,096 slck periods 5 32768_slck fwup shall be low for at least 32,768 slck periods value name description 0 immediate immediate, no debouncing, detected active at least on one slow clock edge 1 3_slck wkupx shall be in its active state for at least 3 slck periods 2 32_slck wkupx shall be in its active state for at least 32 slck periods 3 512_slck wkupx shall be in its active state for at least 512 slck periods 4 4096_slck wkupx shall be in its active state for at least 4,096 slck periods 5 32768_slck wkupx shall be in its active state for at least 32,768 slck periods value name description 0 disable disable the low-power debouncers 1 2_rtcout0 wkup0/10/14/15/tmp0/1/2/3 in active state for at least 2 rtcout0 periods 2 3_rtcout0 wkup0/10/14/15/tmp0/1/2/3 in active state for at least 3 rtcout0 periods 3 4_rtcout0 wkup0/10/14/15/tmp0/1/2/3 in active state for at least 4 rtcout0 periods 4 5_rtcout0 wkup0/10/14/15/tmp0/1/2/3 in active state for at least 5 rtcout0 periods 5 6_rtcout0 wkup0/10/14/15/tmp0/1/2/3 in active state for at least 6 rtcout0 periods 6 7_rtcout0 wkup0/10/14/15/tmp0/1/2/3 in active state for at least 7 rtcout0 periods 7 8_rtcout0 wkup0/10/14/15/tmp0/1/2/3 in active state for at least 8 rtcout0 periods
343 sam4cp [datasheet] 43051e?atpl?08/14 ? distmpclr2: disable gpbr clear command from wkup14/tmp2 pin 0 (enable) = the wkup14/tmp2 input pin can clear the gpbr (if lpdbcclr is enabled) when tamper is detected. 1 (disable) = the wkup14/tmp2 input pin has no effect on the gpbr value (no clear on tamper detection). ? distmpclr3: disable gpbr clear command from wkup15/tmp3 pin 0 (enable) = the wkup15/tmp3 input pin can clear the gpbr (if lpdbcclr is enabled) when tamper is detected. 1 (disable) = the wkup15/tmp3 input pin has no effect on the gpbr value (no clear on tamper detection). ? diststmp1: disable timestamp from wkup10/tmp1 pin 0 (enable) = a tamper detection on wkup10/tmp1 pin generates a timestamp. 1 (disable) = a tamper detection on wkup10/tmp1 does not generate a report in timestamp register. ? diststmp2: disable timestamp from wkup14/tmp2 pin 0 (enable) = a tamper detection on wkup14/tmp2 pin generates a timestamp. 1 (disable) = a tamper detection on wkup14/tmp2 does not generate a report in timestamp register. ? diststmp3: disable timestamp from wkup15/tmp3 pin 0 (enable) = a tamper detection on wkup15/tmp3 pin generates a timestamp. 1 (disable) = a tamper detection on wkup15/tmp3 does not generate a report in timestamp register.
344 sam4cp [datasheet] 43051e?atpl?08/14 20.6.7 supply controller wake-up inputs register name: supc_wuir address: 0x400e1420 access: read/write ? wkupenx: wkupx input enable 0 (disable) = the corresponding wake-up input has no wake-up effect. 1 (enable) = the corresponding wake-up input forces a system wake-up. ? wkuptx: wkupx input type 0 (low) = a low level for a period defined by wkupdbc on the corresponding wake-up input forces a system wake-up. 1 (high) = a high level for a period defined by wkupdbc on the corresponding wake-up input forces a system wake-up. 31 30 29 28 27 26 25 24 wkupt15 wkupt14 wkupt13 wkupt12 wkupt11 wkupt10 wkupt9 wkupt8 23 22 21 20 19 18 17 16 wkupt7 wkupt6 wkupt5 wkupt4 wkupt3 wkupt2 wkupt1 wkupt0 15 14 13 12 11 10 9 8 wkupen15 wkupen14 wkupen13 wkupen12 wkupen11 wkupen10 wkupen9 wkupen8 76543210 wkupen7 wkupen6 wkupen5 wkupen4 wkupen3 wkupen2 wkupen1 wkupen0
345 sam4cp [datasheet] 43051e?atpl?08/14 20.6.8 supply controller status register name: supc_sr address: 0x400e1424 access: read-only note: because of the asynchronism between the slow clock (slck) and the system clock (mck), the status register flag reset is taken into account only 2 slow clock cycles after the read of the supc_sr. ? fwups: fwup wake-up status 0 (no) = no wake-up due to the assertion of the fwup pin has occurred since the last read of supc_sr. 1 (present) = at least one wake-up due to the assertion of the fwup pin has occurred since the last read of supc_sr. ? wkups: wkup wake-up status 0 (no) = no wake-up due to the assertion of the wkup pins has occurred since the last read of supc_sr. 1 (present) = at least one wake-up due to the assertion of the wkup pins has occurred since the last read of supc_sr. ? smws: supply monitor detection wake-up status 0 (no) = no wake-up due to a supply monitor detection has occurred since the last read of supc_sr. 1 (present) = at least one wake-up due to a supply monitor detection has occurred since the last read of supc_sr. ? bodrsts: brownout detector reset status 0 (no) = no core brownout rising edge event has been detected since the last read of supc_sr. 1 (present) = at least one brownout output rising edge event has been detected since the last read of supc_sr. when the voltage remains below the defined threshold, there is no rising edge event at the output of the brownout detection cel l. the rising edge event occurs only when there is a voltage transition below the threshold. ? smrsts: supply monitor reset status 0 (no) = no supply monitor detection has generated a system reset since the last read of supc_sr. 1 (present) = at least one supply monitor detection has generated a system reset since the last read of supc_sr. ? sms: supply monitor status 0 (no) = no supply monitor detection since the last read of supc_sr. 1 (present) = at least one supply monitor detection since the last read of supc_sr. ? smos: supply monitor output status 0 (high) = the supply monitor detected vddio higher than its threshold at its last measurement. 1 (low) = the supply monitor detected vddio lower than its threshold at its last measurement. 31 30 29 28 27 26 25 24 wkupis15 wkupis14 wkupis13 wkupis12 wkupis11 wkupis10 wkupis9 wkupis8 23 22 21 20 19 18 17 16 wkupis7 wkupis6 wkupis5 wkupis4 wkupis3 wkupis2 wkupis1 wkupis0 15 14 13 12 11 10 9 8 buppors lpdbcs1 lpdbcs0 fwupis ? lpdbcs3 lpdbcs2 lcds 76543210 oscsel smos sms smrsts bodrsts smws wkups fwups
346 sam4cp [datasheet] 43051e?atpl?08/14 ? oscsel: 32 khz oscillator selection status 0 (rc) = the slow clock, slck is generated by the embedded 32 khz rc oscillator. 1 (cryst) = the slow clock, slck is generated by the 32 khz crystal oscillator. ? lcds: lcd status 0 (disabled) = lcd controller is disabled. 1 (enabled) = lcd controller is enabled. ? lpdbcs2: low-power debouncer tamper status on wkup14/tmp2 0 (no) = no tamper detection or wake-up due to the assertion of the wkup14/tmp2 pin has occurred since the last read of supc_sr. 1 (present) = at least one tamper detection and wake-up (if enabled by wkupen14) due to the assertion of the wkup14/tmp2 pin has occurred since the last read of supc_sr. the supc interrupt line is asserted while lpdbcs2 is 1. ? lpdbcs3: low-power debouncer tamper status on wkup15/tmp3 0 (no) = no tamper detection or wake-up due to the assertion of the wkup15/tmp3 pin has occurred since the last read of supc_sr. 1 (present) = at least one tamper detection and wake-up (if enabled by wkupen15) due to the assertion of the wkup15/tmp3 pin has occurred since the last read of supc_sr. the supc interrupt line is asserted while lpdbcs2 is 1. ? fwupis: fwup input status 0 (low) = fwup input is tied low. 1 (high) = fwup input is tied high. ? lpdbcs0: low-power debouncer wake-up status on wkup0/tmp0 0 (no) = no tamper detection or wake-up due to the assertion of the wkup0/tmp0 pin has occurred since the last read of supc_sr. 1 (present) = at least one tamper detection and wake-up (if enabled by wkupen0) due to the assertion of the wkup0/tmp0 pin has occurred since the last read of supc_sr. the supc interrupt line is asserted while lpdbcs0 is 1. ? lpdbcs1: low-power debouncer wake-up status on wkup10/tmp1 0 (no) = no tamper detection or wake-up due to the assertion of the wkup10 pin has occurred since the last read of supc_sr. 1 (present) = at least one tamper detection and wake-up (if enabled by wkupen10) due to the assertion of the wkup10/tmp1 pin has occurred since the last read of supc_sr. the supc interrupt line is asserted while lpdbcs1 is 1. ? buppors: backup area power-on reset status 0 (buppor_disabled) = backup por is disabled. 1 (buppor_enabled) = backup por is enabled. note: the value written in bupporen is effective when bupporens is carrying the same value in ?supply controller status register? . ? wkupisx: wkupx input status 0 (dis) = the corresponding wake-up input is disabled, or was inactive at the time the debouncer triggered a wake-up event. 1 (en) = the corresponding wake-up input was active at the time the debouncer triggered a wake-up event.
347 sam4cp [datasheet] 43051e?atpl?08/14 20.6.9 system controller write protection mode register name: sysc_wpmr access: read/write for more information on write protection registers, refer to section 20.5 ?register write protection? . ? wpen: 0: disables the write protection if wpkey corresponds to 0x525443 (sysc in ascii). 1: enables the write protection if wpkey corresponds to 0x525443 (sysc in ascii). see section 20.5 ?register write protection? for the list of registers that can be protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x525443 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
348 sam4cp [datasheet] 43051e?atpl?08/14 21. general-purpose backup registers (gpbr) 21.1 description the system controller embeds 16 general-purpose backup registers. it is possible to generate an immediate clear of the content of general-purpose backup registers 0 to 7 (first half), if a tamper event is detected on one of the tamper pins, tmp0 to tmp3. the content of the other general-purpose backup registers (second half) remains unchanged. the tamper events on pins tmp1 to tmp3 to perform a gpbr clear are configurable in the supply controller. the tmp0 tamper event always performs an immediate clear. the supply controller module must be programmed accordingly. in the register supc_wumr in the supply controller module, lpdbcclr, lpdbcen0, lpdbcen1, lpdbcen2 and and lpdbcen3 bit must be configured to 1 and lpdbc must be other than 0. if a tamper event has been detected, it is not possible to write to the general-purpose backup registers while the lpdbcsx flags are not cleared in the supply controller status register supc_sr. 21.2 embedded characteristics ? 16 32-bit general purpose backup registers 21.3 general purpose backup registers (gpbr) user interface table 21-1. register mapping offset register name access reset 0x0 general purpose backup register 0 sys_gpbr0 read/write 0x00000000 ... ... ... ... ... 0xcc general purpose backup register 15 sys_gpbr15 read/write 0x00000000
349 sam4cp [datasheet] 43051e?atpl?08/14 21.3.1 general purpose backup register x name: sys_gpbrx address: 0x400e1490 access: read/write these registers are reset at first power-up and on each loss of vddbu. ? gpbr_value: value of gpbr x if a tamper event has been detected, it is not possible to write gpbr_value as long as the lpdbcs0 or lpdbcs3 flags have not been cleared in the supply controller status register (supc_sr). 31 30 29 28 27 26 25 24 gpbr_value 23 22 21 20 19 18 17 16 gpbr_value 15 14 13 12 11 10 9 8 gpbr_value 76543210 gpbr_value
350 sam4cp [datasheet] 43051e?atpl?08/14 22. enhanced embedded flash controller (eefc) 22.1 description the enhanced embedded flash controller (eefc) ensures the interface of the flash block with the 32-bit internal bus. its 128-bit or 64-bit wide memory interface increases performa nce. it also manages the programming, erasing, locking and unlocking sequences of the flash using a full set of commands. one of the commands returns the embedded flash descriptor definition that informs the system about the flash organization, thus making the software generic. 22.2 embedded characteristics ? interface of the flash block with the 32-bit internal bus ? increases performance in thumb-2 mode with 128-bit or 64-bit wide memory interface up to 100 mhz ? code loop optimization ? 128 lock bits, each protecting a lock region ? 2 general-purpose gpnvm bits ? one-by-one lock bit programming ? commands protected by a keyword ? erase the entire flash ? erase by plane ? erase by sector ? erase by pages ? possibility of erasing before programming ? locking and unlocking operations ? ecc single and multiple error flags report ? possibility to read the calibration bits 22.3 product dependencies 22.3.1 power management the enhanced embedded flash controller (eefc) is continuously clocked. the power management controller has no effect on its behavior. 22.3.2 interrupt sources the eefc interrupt line is connected to the interrupt controller. using the eefc interrupt requires the interrupt controller to be programmed first. the eefc interrupt is generated only if the value of bit eefc_fmr.frdy is 1. table 22-1. peripheral ids instance id efc 6
351 sam4cp [datasheet] 43051e?atpl?08/14 22.4 functional description 22.4.1 embedded flash organization the embedded flash interfaces directly with the 32-bit internal bus. the embedded flash is composed of: ? one memory plane organized in several pages of the same size. ? two 128-bit or 64-bit read buffers used for code read optimization. ? one 128-bit or 64-bit read buffer used for data read optimization. ? one write buffer that manages page programming. the write buffer size is equal to the page size. this buffer is write-only and accessible all along the 1 mbyte address space, so that each word can be written to its final address. ? several lock bits used to protect write/erase operation on several pages (lock region). a lock bit is associated with a lock region composed of several pages in the memory plane. ? several bits that may be set and cleared through the eefc interface, called general-purpose non-volatile memory bits (gpnvm bits). the embedded flash size, the page size, the organization of lock regions and the definition of gpnvm bits are specific to the device. the eefc returns a descriptor of the flash controller after a get flash descriptor command has been issued by the application (see ?get flash descriptor command? on page 356 ). figure 22-1. embedded flash organization start address page 0 lock region 0 lock region 1 memory plane page (m-1) lock region (n-1) page (n*m-1) start address + flash size -1 lock bit 0 lock bit 1 lock bit (n- 1)
352 sam4cp [datasheet] 43051e?atpl?08/14 22.4.2 read operations an optimized controller manages embedded flash reads, thus increasing performance when the processor is running in thumb-2 mode by means of the 128- or 64-bit wide memory interface. the flash memory is accessible through 8-, 16- and 32-bit reads. as the flash block size is smaller than the address sp ace reserved for the internal memory area, the embedded flash wraps around the address space and appears to be repeated within it. the read operations can be performed with or without wait states. wait states must be programmed in the field fws (flash read wait state) in the flash mode register (eefc_fmr). defining fws as 0 enables the single-cycle access of the embedded flash. refer to the ?electrical characteristics? section for more details. 22.4.2.1 128-bit or 64-bit access mode by default, the read accesses of the flash are performed through a 128-bit wide memory interface. it improves system performance especially when two or three wait states are needed. for systems requiring only 1 wait state, or to focus on current consumption rather than performance, the user can select a 64-bit wide memory access via the bit eefc_fmr.fam. refer to the ?electrical characteristics? section for more details. 22.4.2.2 code read optimization code read optimization is enabled if the bit eefc_fmr.scod is cleared. a system of 2 x 128-bit or 2 x 64-bit buffers is added in order to optimize sequential code fetch. note: immediate consecutive code read accesses are not mandatory to benefit from this optimization. the sequential code read optimiza tion is enabled by default. if the bit eefc_fmr.scod is set to 1, these buffers are disabled and the sequential code read is no longer optimized. another system of 2 x 128-bit or 2 x 64-bit buffers is added in order to optimize loop code fetch. refer to ?code loop optimization? on page 353 for more details. figure 22-2. code read optimization for fws = 0 note: when fws is equal to 0, all the accesses are performed in a single-cycle access. flash access buffer 0 (128bits) master clock arm request (32-bit) xxx data to arm bytes 0-15 bytes 16-31 bytes 32-47 bytes 0-15 buffer 1 (128bits) bytes 32-47 bytes 0-3 bytes 4-7 bytes 8-11 bytes 12-15 bytes 16-19 bytes 20-23 bytes 24-27 xxx xxx bytes 16-31 @byte 0 @byte 4 @byte 8 @byte 12 @byte 16 @byte 20 @byte 24 @byte 28 @byte 32 bytes 28-31
353 sam4cp [datasheet] 43051e?atpl?08/14 figure 22-3. code read optimization for fws = 3 note: when fws is included between 1 and 3, in case of sequential reads, the first access takes (fws+1) cycles, the other ones only 1 cycle. 22.4.2.3 code loop optimization code loop optimization is enabled when the bit eefc_fmr.cloe is set to 1. when a backward jump is inserted in the code, the pipeline of the sequential optimization is broken and becomes inefficient. in this case, the loop code read optimization takes over from the sequential code read optimization to prevent the insertion of wait states. the loop code read optimization is enabled by default. in eefc_fmr, if the bit cloe is reset to 0 or the bit scod is set to 1, these buffers are disabled and the loop code read is not optimized. when code loop optimization is enabled, if inner loop body instructions l 0 to l n are positioned from the 128-bit flash memory cell m b0 to the memory cell m p1 , after recognition of a first backward branch, the first two flash memory cells m b0 and m b1 targeted by this branch are cached for fast access from the processor at the next loop iteration. then by combining the sequentia l prefetch (described in section 22.4.2.2 ?code read optimization? ) through the loop body with the fast read access to the loop entry cache, the entire loop can be iterated with no wait state. figure 22-4 illustrates code loop optimization. figure 22-4. code loop optimization flash access buffer 0 (128bits) master clock arm request (32-bit) data to arm buffer 1 (128bits) 0-3 xxx xxx bytes 16-31 @byte 0 @4 @8 bytes 0-15 bytes 16-31 bytes 32-47 bytes 48-63 xxx bytes 0-15 4-7 8-11 12-15 @12 @16 @20 24-27 28-31 32-35 36-39 16-19 20-23 40-43 44-47 @24 @28 @32 @36 @40 @44 @48 @52 bytes 32-47 48-51 l n l n-1 l n-2 l n-3 l n-4 l n-5 l 5 l 4 l 3 l 2 l 1 l 0 b 1 b 2 b 3 b 4 b 5 b 6 b 7 b 0 p 1 p 2 p 3 p 4 p 5 p 6 p 7 p 0 m b 0 m b0 m b1 m p0 m p1 backward address jump 2x128-bit loop entry cache 2x128-bit prefetch buffer l 0 loop entry instruction l n loop end instruction flash memory 128-bit words m b0 branch cache 0 m b1 branch cache 1 m p0 prefetch buffer 0 m p1 prefetch buffer 1
354 sam4cp [datasheet] 43051e?atpl?08/14 22.4.2.4 data read optimization the organization of the flash in 128 bits (or 64 bits) is associated with two 128-bit (or 64-bit) prefetch buffers and one 128-bit (or 64-bit) data read buffer, thus providing maximum system performance. this buffer is added in order to store the requested data plus all the data contained in the 128-bit (64-bit) aligned data. this speeds up sequential data reads if, for example, fws is equal to 1 (see figure 22-5 ). the data read optimization is enabled by default. if the bit eefc_fmr.scod is set to 1, this buffer is disabled and the data read is no longer optimized. note: no consecutive data read accesses are mandatory to benefit from this optimization. figure 22-5. data read optimization for fws = 1 22.4.3 flash commands the eefc offers a set of commands to manage programming the flash memory, locking and unlocking lock regions, consecutive programming, locking and full flash erasing, etc. flash access buffer (128bits) master clock arm request (32-bit) xxx data to arm bytes 0-15 bytes 16-31 bytes 0-15 bytes 0-3 4-7 8-11 12-15 16-19 20-23 xxx bytes 16-31 @byte 0 @4 @8 @12 @16 @20 @ 24 @28 @32 @36 xxx bytes 32-47 24-27 28-31 32-35 table 22-2. set of commands command value mnemonic get flash descriptor 0x00 getd write page 0x01 wp write page and lock 0x02 wpl erase page and write page 0x03 ewp erase page and write page then lock 0x04 ewpl erase all 0x05 ea erase pages 0x07 epa set lock bit 0x08 slb clear lock bit 0x09 clb get lock bit 0x0a glb set gpnvm bit 0x0b sgpb clear gpnvm bit 0x0c cgpb get gpnvm bit 0x0d ggpb start read unique identifier 0x0e stui stop read unique identifier 0x0f spui get calib bit 0x10 gcalb
355 sam4cp [datasheet] 43051e?atpl?08/14 in order to perform one of these commands, select the desired command using the fcmd field in the flash command register (eefc_fcr). as soon as eefc_fcr is written, the frdy flag and the fvalue field in the flash result register (eefc_frr) are automatically cleared. once the current command has completed, the frdy flag is automatically set. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the corresponding interrupt line of the interrupt controller is activated. (note that this is true for all commands except for the stui command. the frdy flag is not set when the stui command has completed). all the commands are protected by the same keyword, which must be written in the eight highest bits of eefc_fcr. writing eefc_fcr with data that does not contain the correct key and/or with an invalid command has no effect on the whole memory plane, but the fcmde flag is set in the flash status register (eefc_fsr). this flag is automatically cleared by a read access to eefc_fsr. when the current command writes or erases a page in a locked region, the command has no effect on the whole memory plane, but the flocke flag is set in eefc_fsr. this flag is automatically cleared by a read access to eefc_fsr. erase sector 0x11 es write user signature 0x12 wus erase user signature 0x13 eus start read user signature 0x14 stus stop read user signature 0x15 spus table 22-2. set of commands (continued) command value mnemonic
356 sam4cp [datasheet] 43051e?atpl?08/14 figure 22-6. command state chart 22.4.3.1 get flash descriptor command this command provides the system with information on the flash organization. the system can take full advantage of this information. for instance, a device could be replaced by one with more flash capacity, and so the software is able to adapt itself to the new configuration. to get the embedded flash descriptor, the application writes the getd command in eefc_fcr. the first word of the descriptor can be read by the software application in eefc_frr as soon as the frdy flag in eefc_fsr rises. the next reads of eefc_frr provide the following word of the descriptor. if extra read operations to eefc_frr are done after the last word of the descriptor has been returned, the eefc_frr value is 0 until the next valid command. no yes read status: eefc_fsr no read status: eefc_fsr yes yes no yes no bad keyword violation command successfull check if frdy flag set write fcmd and pagenb in flash command register check if frdy flag set check if flocke flag set check if fcmde flag set locking region violation
357 sam4cp [datasheet] 43051e?atpl?08/14 22.4.3.2 write commands several commands are used to program the flash. only 0 values can be programmed using flash technology; 1 is the erased value. in order to program words in a page, the page must first be erased. commands are available to erase the full memory plane or a given number of pages. with the ewp and ewpl commands, a page erase is done automatically before a page programming. after programming, the page (the entire lock region) can be locked to prevent miscellaneous write or erase sequences. the lock bit can be automatically set after page programming using wpl or ewpl commands. data to be programmed in the flash must be written in an internal latch buffer before writing the programming command in eefc_fcr. data can be written at their final destination address, as the latch buffer is mapped into the flash memory address space and wraps around within this flash address space. byte and half-word ahb accesses to the latch buffer are not allowed. only 32-bit word accesses are supported. 32-bit words must be written continuously, in either ascending or descending order. writing the latch buffer in a random order is not permitted. this prevents mapping a c-code st ructure to the latch buffer and accessing the data of the structure in any order. it is instead recommended to fill in a c-code structure in sram and copy it in the latch buffer in a continuous order. write operations in the latch buffer are performed with the number of wait states programmed for reading the flash. the latch buffer is automatically re-initialized, i.e., written with logical 1, after execution of each programming command. the programming sequence is as follows: 1. write the data to be programmed in the latch buffer. 2. write the programming command in eefc_fcr. this automatically clears the frdy bit in eefc_fsr. 3. when flash programming is completed, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by set- ting the bit eefc_fmr.frdy, the interrupt line of the eefc is activated. three errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? lock error: the page to be programmed belongs to a locked region. a command must be run previously to unlock the corresponding region. ? flash error: when programming is completed, the writeverify test of the flash memory has failed. only one page can be programmed at a time. it is possible to program all the bits of a page (full page programming) or only some of the bits of the page (partial page programming). depending on the number of bits to be programmed with in the page, the eefc adapts the write operations required to program the flash. table 22-3. flash descriptor definition symbol word index description fl_id 0 flash interface description fl_size 1 flash size in bytes fl_page_size 2 page size in bytes fl_nb_plane 3 number of planes fl_plane[0] 4 number of bytes in the first plane. fl_nb_lock 4 + fl_nb_plane number of lock bits. a bit is associated with a lock region. a lock bit is used to prevent write or erase operations in the lock region. fl_lock[0] 4 + fl_nb_plane + 1 number of bytes in the first lock region.
358 sam4cp [datasheet] 43051e?atpl?08/14 when the programming page command is given, the eefc starts the programming sequence and all the bits written at 0 in the latch buffer are cleared in the flash memory array. during programming, i.e. until eefc_fsr.fdry rises, access to the flash is not allowed. full page programming to program a full page, all the bits of the page must be erased before writing the latch buffer and launching the wp command. the latch buffer must be written in ascending order, starting from the first address of the page. see figure 22- 7, "full page programming" . partial page programming to program only part of a page using the wp command, the following constraints must be respected: ? data to be programmed must be contained in integer multiples of 64-bit address-aligned words. ? 64-bit words can be programmed only if all the corresponding bits in the flash array are erased (at logical value 1). see figure 22-8, "partial page programming" . programming bytes individual bytes can be programmed using the partial page programming mode. in this case, an area of 64 bits must be reserved for each byte, as shown in figure 22-9, "programming bytes in the flash" . figure 22-7. full page programming ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c before programming: unerased page in flash array ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe step 1: flash array after page erase ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff address space for page n address space for latch buffer step 2: writing a page in the latch buffer de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca ca fe ca fe 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c address space for page n step 3: page in flash array after issuing wp command and frdy=1 de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca de ca ff ff ff ff 32 bits wide 32 bits wide
359 sam4cp [datasheet] 43051e?atpl?08/14 figure 22-8. partial page programming figure 22-9. programming bytes in the flash 32 bits wide 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c step 2: flash array after programming 64-bit at address 0xx08 (write latch buffer + wp) ca fe ca fe ca fe ca fe ff ff ff ff ff ff ff ff address space for page n ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff step 1: flash array after page erase c a fe c a f e c a fe c a f e 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c step 3: flash array after programming a second 64-bit data at address 0xx00 (write latch buffer + wp) ca fe ca fe ca fe ca fe ff ff ff ff ff ff ff ff ff ff ff ff ca fe ca fe ca fe ca fe 32 bits wide 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c step 4: flash array after programming a 128-bit data word at address 0xx10 (write latch buffer + wp) ca fe ca fe ca fe ca fe ff ff ff ff ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe ca fe 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c ff ff ff ff ff ff ff ff address space for page n step 1: flash array after programming first byte (0xaa) 64-bit used at address 0xx00 (write latch buffer + wp) ff ff ff ff xx xx xx xx xx xx xx aa 32 bits wide ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0xx00 0xx04 0xx08 0xx0c 0xx10 0xx14 0xx18 0xx1c ff ff ff ff xx xx xx xx xx xx xx aa step 2: flash array after programming second byte (0x55) 64-bit used at address 0xx08 (write latch buffer + wp) xx xx xx xx xx xx xx 55 note: the byte location shown here is for example only, it can be any byte location within a 64-bit word. 4 x 32 bits = 1 flash word 4 x 32 bits = 1 flash word
360 sam4cp [datasheet] 43051e?atpl?08/14 22.4.3.3 erase commands erase commands are allowed only on unlocked regions. depending on the flash memory, several commands can be used to erase the flash: ? erase all memory (ea): all memory is erased. the processor must not fetch code from the flash memory. ? erase pages (epa): 8 or 16 pages are erased in the flash sector selected.the first page to be erased is specified in the farg[15:2] field of the mc_fcr. the first page number must be modulo 8,16 or 32 depending on the number of pages to erase at the same time. ? erase sector (es): a full memory sector is erased. sector size depends on the flash memory. farg must be set with a page number that is in the sector to be erased. if the processor is fetching code from the flash memory while the epa or es command is being performed, the processor accesses will be stalled until the epa command is completed. to avoid stalling the processor, the code can be run out of internal sram. the erase sequence is: 1. erase starts as soon as one of the erase commands and the farg field are written in eefc_fcr. ? for the epa command, the two lowest bits of the farg field define the number of pages to be erased (farg [1:0]): 2. when programming is completed, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. three errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? lock error: at least one page to be erased belongs to a locked region. the erase command has been refused, no page has been erased. a command must be run previously to unlock the corresponding region. ? flash error: at the end of the programming, the eraseverify test of the flash memory has failed. 22.4.3.4 lock bit protection lock bits are associated with several pages in the embedded flash memory plane. this defines lock regions in the embedded flash memory plane. they prevent writing/erasing protected pages. the lock sequence is: 1. the set lock bit (slb) command and a page number to be protected are written in eefc_fcr. 2. when the locking completes, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. 3. the result of the slb command can be checked running a get lock bit (glb) command. note: the value of the farg argument passed together with slb command must not exceed the higher lock bit index available in the product. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eraseverify or writeverify test of the flash memory has failed. table 22-4. farg field for epa command farg[1:0] number of pages to be erased with epa command 0 4 pages (only valid for small 8 kb sectors) 1 8 pages 2 16 pages 3 32 pages (only valid for small 8 kb sectors)
361 sam4cp [datasheet] 43051e?atpl?08/14 it is possible to clear lock bits previously set. then the locked region can be erased or programmed. the unlock sequence is: 1. the clear lock bit (clb) command and a page number to be unprotected are written in eefc_fcr. 2. when the unlock completes, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. note: the value of the farg argument passed together with clb command must not exceed the higher lock bit index available in the product. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eraseverify or writeverify test of the flash memory has failed. the status of lock bits can be returned by the eefc. the get lock bit status sequence is: 1. the get lock bit (glb) command is written in eefc_fcr. the farg field is meaningless. 2. lock bits can be read by the software application in eefc_frr. the first word read corresponds to the 32 first lock bits, next reads providing the next 32 lock bits as long as it is meaningful. extra reads to eefc_frr return 0. for example, if the third bit of the first word read in eefc_frr is set, then the third lock region is locked. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eraseverify or writeverify test of the flash memory has failed. note: access to the flash in read is permitted when a set, clear or get lock bit command is performed. 22.4.3.5 gpnvm bit gpnvm bits do not interfere with the embedded flash memory plane. refer to specific product details for information on gpnvm bit action. the set gpnvm bit sequence is: 1. start the set gpnvm bit (sgpb) command by writing eefc_fcr with the sgpb command and the number of the gpnvm bits to be set. 2. when the gpnvm bit is set, the bit eefc_fsr.frdy rises. if an interrupt was enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. 3. the result of the sgpb command can be checked by running a get gpnvm bit (ggpb) command. note: the value of the farg argument passed together with sgpb command must not exceed the higher gpnvm index available in the product. flash data content is not altered if farg exceeds the limit. command error is detected only if farg is greater than 8. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eraseverify or writeverify test of the flash memory has failed. it is possible to clear gpnvm bits previously set. the clear gpnvm bit sequence is: 1. start the clear gpnvm bit (cgpb) command by writing eefc_fcr with cgpb and the number of the gpnvm bits to be cleared. 2. when the clear completes, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. note: the value of the farg argument passed together with cgpb command must not exceed the higher gpnvm index available in the product. flash data content is not altered if farg exceeds the limit. command error is detected only if farg is greater than 8. two errors can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eraseverify or writeverify test of the flash memory has failed.
362 sam4cp [datasheet] 43051e?atpl?08/14 the status of gpnvm bits can be returned by the eefc. the sequence is: 1. start the get gpnvm bit command by writing eefc_fcr with ggpb. the farg field is meaningless. 2. gpnvm bits can be read by the software application in eefc_frr. the first word read corresponds to the 32 first gpnvm bits, following reads provide the next 32 gpnvm bits as long as it is meaningful. extra reads to eefc_frr return 0. for example, if the third bit of the first word read in eefc_frr is set, then the third gpnvm bit is active. one error can be detected in eefc_fsr after a programming sequence: ? command error: a bad keyword has been written in eefc_fcr. note: access to the flash in read is permitted when a set, clear or get gpnvm bit command is performed. 22.4.3.6 calibration bit calibration bits do not interfere with the embedded flash memory plane. the calibration bits cannot be modified. the status of calibration bits are returned by the eefc. the sequence is: 1. issue the get calib bit command by writing eefc_fcr with gcalb (see table 22-2 ). the farg field is meaningless. 2. calibration bits can be read by the software application in eefc_frr. the first word read corresponds to the first 32 calibration bits. the following reads provide the next 32 calibration bits as long as it is meaningful. extra reads to eefc_frr return 0. the 4/8/12 mhz fast rc oscillator is calibrated in production. this calibration can be read through the get calib bit command. the table below shows the bit implementation for each frequency: the rc calibration for the 4 mhz is set to ?1000000?. 22.4.3.7 security bit protection when the security is enabled, access to the flash, either through the jtag/swd interface or through the fast flash programming interface, is forbidden. this ensures the confidentiality of the code programmed in the flash. the security bit is gpnvm0. disabling the security bit can only be achieved by asserting the erase pin at 1, and after a full flash erase is performed. when the security bit is deactivated, all accesses to the flash are permitted. 22.4.3.8 unique identifier each part is programmed with a 2x512-bytes unique identifier. it can be used to generate keys for example. to read the unique identifier the sequence is: 1. send the start read unique identifier (stui) command by writing eefc_fcr with the stui command. 2. when the unique identifier is ready to be read, the bit eefc_fsr.frdy falls. 3. the unique identifier is located at the address 0x1000000-0x100000f, in the first 128 bits of the flash memory mapping. 4. to stop the unique identifier mode, the user needs to send the stop read unique identifier (spui) command by writing eefc_fcr with the spui command. 5. when the spui command has been performed, the bit eefc_fsr.frdy rises. if an interrupt was enabled by set- ting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. note that during the sequence, the software cannot run out of flash. table 22-5. calibration bit indexes rc calibration frequency eefc_frr bits 8 mhz output [28 - 22] 12 mhz output [38 - 32]
363 sam4cp [datasheet] 43051e?atpl?08/14 22.4.3.9 user signature each part contains a user signature of 512 bytes. it can be used for storage. read, write and erase of this area is allowed. to read the user signature, the sequence is as follows: 1. send the start read user signature (stus) command by writing eefc_fcr with the stus command. 2. when the user signature is ready to be read, the bit eefc_fsr.frdy falls. 3. the user signature is located in the first 512 bytes of the flash memory mapping, thus, at the address 0x1000000-0x10001ff. 4. to stop the user signature mode, the user needs to send the stop read user signature (spus) command by writing eefc_fcr with the spus command. 5. when the spus command has been performed, the bit eefc_fsr.frdy rises. if an interrupt was enabled by setting the bit eefc_fmr.frdy, the interrupt line of the interrupt controller is activated. note that during the sequence, the software cannot run out of flash or the second plane, in case of dual plane. one error can be detected in eefc_fsr after this sequence: ? command error: a bad keyword has been written in eefc_fcr. to write the user signature, the sequence is: 1. write the full page, at any page address, within the internal memory area address space. 2. send the write user signature (wus) command by writing eefc_fcr with the wus command. 3. when programming is completed, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the corresponding interrupt line of the interrupt controller is activated. two errors can be detected in eefc_fsr after this sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the writeverify test of the flash memory has failed. to erase the user signature, the sequence is: 1. send the erase user signature (eus) command by writing the eefc_fcr with the eus command. 2. when programming is completed, the bit eefc_fsr.frdy rises. if an interrupt has been enabled by setting the bit eefc_fmr.frdy, the corresponding interrupt line of the interrupt controller is activated. two errors can be detected in eefc_fsr after this sequence: ? command error: a bad keyword has been written in eefc_fcr. ? flash error: at the end of the programming, the eraseverify test of the flash memory has failed. 22.4.3.10 ecc errors and corrections the flash embeds an ecc module able to correct one unique error and able to detect two errors. the errors are detected while a read access is performed into memory array and stored in eefc_fsr (see section 22.5.3 ?eefc flash status register? on page 368 ). the error report is kept until eefc_fsr is read. there is one flag for a unique error on lower half part of the flash word (64 lsb) and one flag for the upper half part (msb). the multiple errors are reported in the same way. due to the anticipation mechanism to improve bandwidth throughput on instruction fetch, a reported error can be located in the next sequential flash word compared to the location of the instruction being executed, which is located in the previously fetched flash word. if a software routine processes the error detection independently from the main software routine, the entire flash located software must be rewritten because there is no storage of the error location. if only a software routine is running to program and check pages by reading eefc_fsr, the situation differs from previous case. performing a check for ecc unique errors just after page programming completion involves a read of the newly programmed page. this read sequence is viewed as data accesses and is not optimized by the flash controller. thus, in case of unique error, only the current page must be reprogrammed.
364 sam4cp [datasheet] 43051e?atpl?08/14 22.5 enhanced embedded flash controller (eefc) user interface the user interface of the enhanced embedded flash controller (eefc) is integrated within the system controller with base address 0x400e0a00 . table 22-6. register mapping offset register name access reset state 0x00 eefc flash mode register eefc_fmr read/write 0x0400_0000 0x04 eefc flash command register eefc_fcr write-only ? 0x08 eefc flash status register eefc_fsr read-only 0x00000001 0x0c eefc flash result register eefc_frr read-only 0x0 0x10 - 0x14 reserved ? ? ? 0x18 - 0xe4 reserved ? ? ?
365 sam4cp [datasheet] 43051e?atpl?08/14 22.5.1 eefc flash mode register name: eefc_fmr address: 0x400e0a00 access: read/write ? frdy: ready interrupt enable 0: flash ready does not generate an interrupt. 1: flash ready (to accept a new command) generates an interrupt. ? fws: flash wait state this field defines the number of wait states for read and write operations: number of cycles for read/write operations = fws+1. ? scod: sequential code optimization disable 0: the sequential code optimization is enabled. 1: the sequential code optimization is disabled. no flash read should be done during change of this register. ? fam: flash access mode 0: 128-bit access in read mode only, to enhance access speed. 1: 64-bit access in read mode only, to enhance power consumption. no flash read should be done during change of this register. ? cloe: code loop optimization enable 0: the opcode loop optimization is disabled. 1: the opcode loop optimization is enabled. no flash read should be done during change of this register. 31 30 29 28 27 26 25 24 ????? cloe ? fam 23 22 21 20 19 18 17 16 ??????? scod 15 14 13 12 11 10 9 8 ???? fws 76543210 ??????? frdy
366 sam4cp [datasheet] 43051e?atpl?08/14 22.5.2 eefc flash command register name: eefc_fcr address: 0x400e0a04 access: write-only ? fcmd: flash command 31 30 29 28 27 26 25 24 fkey 23 22 21 20 19 18 17 16 farg 15 14 13 12 11 10 9 8 farg 76543210 fcmd value name description 0x00 getd get flash descriptor 0x01 wp write page 0x02 wpl write page and lock 0x03 ewp erase page and write page 0x04 ewpl erase page and write page then lock 0x05 ea erase all 0x07 epa erase pages 0x08 slb set lock bit 0x09 clb clear lock bit 0x0a glb get lock bit 0x0b sgpb set gpnvm bit 0x0c cgpb clear gpnvm bit 0x0d ggpb get gpnvm bit 0x0e stui start read unique identifier 0x0f spui stop read unique identifier 0x10 gcalb get calib bit 0x11 es erase sector 0x12 wus write user signature 0x13 eus erase user signature 0x14 stus start read user signature 0x15 spus stop read user signature
367 sam4cp [datasheet] 43051e?atpl?08/14 ? farg: flash command argument ? fkey: flash writing protection key getd, glb, ggpb, stui, spui, gcalb, wus, eus, stus, spus, ea commands requiring no argument, including erase all command farg is meaningless, must be written with 0 es erase sector command farg must be written with any page number within the sector to be erased epa erase pages command farg[1:0] defines the number of pages to be erased the start page must be written in farg[15:2] farg[1:0]=0: four pages to be erased. farg[15:2]=page_number modulo 4 farg[1:0]=1: eight pages to be erased. farg[15:2]=page_number modulo 8 farg[1:0]=2: sixteen pages to be erased. farg[15:2]=page_number modulo 16 farg[1:0]=3: thirty-two pages to be erased. farg[15:2]=page_number modulo 32 refer to table 22-4 on page 360 wp, wpl, ewp, ewpl programming commands farg must be written with the page number to be programmed slb, clb lock bit commands farg defines the page number to be locked or unlocked sgpb, cgpb gpnvm commands farg defines the gpnvm number to be programmed value name description 0x5a passwd the 0x5a value enables the command defined by the bits of the register. if the field is written with a different value, the write is not performed and no action is started
368 sam4cp [datasheet] 43051e?atpl?08/14 22.5.3 eefc flash status register name: eefc_fsr address: 0x400e0a08 access: read-only ? frdy: flash ready status 0: the eefc is busy. 1: the eefc is ready to start a new command. when set, this flag triggers an interrupt if the frdy flag is set in eefc_fmr. this flag is automatically cleared when the eefc is busy. ? fcmde: flash command error status 0: no invalid commands and no bad keywords were written in eefc_fmr. 1: an invalid command and/or a bad keyword was/were written in eefc_fmr. this flag is automatically cleared when eefc_fsr is read or eefc_fcr is written. ? flocke: flash lock error status 0: no programming/erase of at least one locked region has happened since the last read of eefc_fsr. 1: programming/erase of at least one locked region has happened since the last read of eefc_fsr. this flag is automatically cleared when eefc_fsr is read or eefc_fcr is written. ? flerr: flash error status 0: no flash memory error occurred at the end of programming (eraseverify or writeverify test has passed). 1: a flash memory error occurred at the end of programming (eraseverify or writeverify test has failed). ? ueccelsb: unique ecc error on lsb part of the memory flash data bus 0: no unique error detected on 64 lsb data bus of the flash memory since the last read of eefc_fsr. 1: one unique error detected but corrected on 64 lsb data bus of the flash memory since the last read of eefc_fsr. ? meccelsb: multiple ecc error on lsb part of the memory flash data bus 0: no multiple error detected on 64 lsb part of the flash memory data bus since the last read of eefc_fsr. 1: multiple errors detected and not corrected on 64 lsb part of the flash memory data bus since the last read of eefc_fsr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???? meccemsb ueccemsb meccelsb ueccelsb 15 14 13 12 11 10 9 8 ???????? 76543210 ???? flerr flocke fcmde frdy
369 sam4cp [datasheet] 43051e?atpl?08/14 ? ueccemsb: unique ecc error on msb part of the memory flash data bus 0: no unique error detected on 64 msb data bus of the flash memory since the last read of eefc_fsr. 1: one unique error detected but corrected on 64 msb data bus of the flash memory since the last read of eefc_fsr. ? meccemsb: multiple ecc error on msb part of the memory flash data bus 0: no multiple error detected on 64 msb part of the flash memory data bus since the last read of eefc_fsr. 1: multiple errors detected and not corrected on 64 msb part of the flash memory data bus since the last read of eefc_fsr.
370 sam4cp [datasheet] 43051e?atpl?08/14 22.5.4 eefc flash result register name: eefc_frr address: 0x400e0a0c access: read-only ? fvalue: flash result value the result of a flash command is returned in this register. if th e size of the result is greater than 32 bits, then the next re sulting value is accessible at the next register read. 31 30 29 28 27 26 25 24 fvalue 23 22 21 20 19 18 17 16 fvalue 15 14 13 12 11 10 9 8 fvalue 76543210 fvalue
371 sam4cp [datasheet] 43051e?atpl?08/14 23. fast flash programming interface (ffpi) 23.1 description the fast flash programming interface (ffpi) provides parallel high-volume programming using a standard gang programmer. the parallel interface is fully handshaked and the device is considered to be a standard eeprom. additionally, the parallel protocol offers an optimized access to all the embedded flash functionalities. although the fast flash programming mode is a dedicated mode for high volume programming, this mode is not designed for in-situ programming. 23.2 embedded characteristics ? programming mode for high-volume flash programming using gang programmer ? offers read and write access to the flash memory plane ? enables control of lock bits and general-purpose nvm bits ? enables security bit activation ? disabled once security bit is set ? parallel fast flash programming interface ? provides an 16-bit parallel interface to program the embedded flash ? full handshake protocol 23.3 parallel fast flash programming 23.3.1 device configuration in fast flash programming mode, the device is in a specific test mode. only a certain set of pins is significant. the rest of the pios are used as inputs with a pull-up. the crystal oscillator is in bypass mode. other pins must be left unconnected. figure 23-1. parallel programming interface ncmd pgmncmd rdy pgmrdy noe pgmnoe nvalid pgmnvalid mode[3:0] pgmm[3:0] data[15:0] pgmd[15:0] xin tst vddio pgmen0 pgmen1 0 - 50mhz vddio vddcore vddio vddpll vddbu gnd vddio
372 sam4cp [datasheet] 43051e?atpl?08/14 23.3.2 signal names table 23-1. signal description list signal name function type active level comments pin (lqfp176) power vddio i/o lines power supply power vddcore core power supply power vddpll pll power supply power gnd ground power clocks xin main clock input. this input can be tied to gnd. in this case, the device is clocked by the internal rc oscillator. input 32 khz to 50 mhz test tst test mode select input high must be connected to vddio pgmen0 test mode select input high must be connected to vddio 158 pgmen1 test mode select input high must be connected to vddio 174 pio pgmncmd valid command available input low pulled-up input at reset 145 pgmrdy 0: device is busy 1: device is ready for a new command output high pulled-up input at reset 144 pgmnoe output enable (active high) input low pulled-up input at reset 111 pgmnvalid 0: data[15:0] is in input mode 1: data[15:0] is in output mode output low pulled-up input at reset 176 pgmm0 specifies data type (see table 23-2 ) input pulled-up input at reset 45 pgmm1 126 pgmm2 127 pgmm3 128 pgmd0 bi-directional data bus input/output pulled-up input at reset 147 pgmd1 130 pgmd2 131 pgmd3 133 pgmd4 134 pgmd5 135 pgmd6 43 pgmd7 42 pgmd8 40 pgmd9 115 pgmd10 116 pgmd11 124 pgmd12 38 pgmd13 36 pgmd14 34 pgmd15 110
373 sam4cp [datasheet] 43051e?atpl?08/14 depending on the mode settings, data is latched in different internal registers. when mode is equal to cmde, then a new command (strobed on data[15:0] signals) is stored in the command register. 23.3.3 entering programming mode the following algorithm puts the device in parallel programming mode: ? apply the supplies as described in table 23-1 . ? apply xin clock within t por_reset if an external clock is available. ? wait for t por_reset ? start a read or write handshaking. note: after reset, the device is clocked by the internal rc oscillator. before clearing rdy signal, if an external clock (>32 khz) is connected to xin, then the device switches on the external clock. else, xin input is not considered. a higher frequency on xin speeds up the programmer handshake. table 23-2. mode coding mode[3:0] symbol data 0000 cmde command register 0001 addr0 address register lsbs 0010 addr1 0101 data data register default idle no register table 23-3. command bit coding data[15:0] symbol command executed 0x0011 read read flash 0x0012 wp write page flash 0x0022 wpl write page and lock flash 0x0032 ewp erase page and write page 0x0042 ewpl erase page and write page then lock 0x0013 ea erase all 0x0014 slb set lock bit 0x0024 clb clear lock bit 0x0015 glb get lock bit 0x0034 sgpb set general purpose nvm bit 0x0044 cgpb clear general purpose nvm bit 0x0025 ggpb get general purpose nvm bit 0x0054 sse set security bit 0x0035 gse get security bit 0x001f wram write memory 0x001e gve get version
374 sam4cp [datasheet] 43051e?atpl?08/14 23.3.4 programmer handshaking an handshake is defined for read and write operations. when th e device is ready to start a new operation (rdy signal set), the programmer starts the handshake by clearing the ncmd signal. the handshaking is achieved once ncmd signal is high and rdy is high. 23.3.4.1 write handshaking for details on the write handshaking sequence, refer to figure 23-2 and table 23-4 . figure 23-2. parallel programming timing, write sequence 23.3.4.2 read handshaking for details on the read handshaking sequence, refer to figure 23-3 and table 23-5 . figure 23-3. parallel programming timing, read sequence table 23-4. write handshake step programmer action device action data i/o 1 sets mode and data signals waits for ncmd low input 2 clears ncmd signal latches mode and data input 3 waits for rdy low clears rdy signal input 4 releases mode and data signals executes command and polls ncmd high input 5 sets ncmd signal executes command and polls ncmd high input 6 waits for rdy high sets rdy input ncmd rdy noe nvalid data[15:0] mode[3:0] 1 2 3 4 5 ncmd rdy noe nvalid data[15:0] mode[3:0] 1 2 3 4 5 6 7 9 8 addr adress in z data out 10 11 xin 12 13
375 sam4cp [datasheet] 43051e?atpl?08/14 23.3.5 device operations several commands on the flash memory are available. these commands are summarized in table 23-3 on page 373 . each command is driven by the programmer through the parallel interface running several read/write handshaking sequences. when a new command is executed, the previous one is automatically achieved. thus, chaining a read command after a write automatically flushes the load buffer in the flash. 23.3.5.1 flash read command this command is used to read the contents of the flash mem ory. the read command can start at any valid address in the memory plane and is optimized for consecutive reads. read handshaking can be chained; an internal address buffer is automatically increased. table 23-5. read handshake step programmer action device action data i/o 1 sets mode and data signals waits for ncmd low input 2 clears ncmd signal latch mode and data input 3 waits for rdy low clears rdy signal input 4 sets data signal in tristate waits for noe low input 5 clears noe signal tristate 6 waits for nvalid low sets data bus in output mode and outputs the flash contents output 7 clears nvalid signal output 8 reads value on data bus waits for noe high output 9 sets noe signal output 10 waits for nvalid high sets data bus in input mode x 11 sets data in output mode sets nvalid signal input 12 sets ncmd signal waits for ncmd high input 13 waits for rdy high sets rdy signal input table 23-6. read command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde read 2 write handshaking addr0 memory address lsb 3 write handshaking addr1 memory address 4 read handshaking data *memory address++ 5 read handshaking data *memory address++ ... ... ... ... n write handshaking addr0 memory address lsb n+1 write handshaking addr1 memory address n+2 read handshaking data *memory address++ n+3 read handshaking data *memory address++ ... ... ... ...
376 sam4cp [datasheet] 43051e?atpl?08/14 23.3.5.2 flash write command this command is used to write the flash contents. the flash memory plane is organized into several pages. data to be written are stored in a load buffer that corresponds to a flash memory page. the load buffer is automatically flushed to the flash: ? before access to any page other than the current one ? when a new command is validated (mode = cmde) the write page command (wp) is optimized for consecutive writes. write handshaking can be chained; an internal address buffer is automatically increased. the flash command write page and lock (wpl) is equivalent to the flash write command. however, the lock bit is automatically set at the end of the flash write operation. as a lock region is composed of several pages, the programmer writes to the first pages of the lock region using flash write commands and writes to the last page of the lock region using a flash write and lock command. the flash command erase page and write (ewp) is equivalent to the flash write command. however, before programming the load buffer, the page is erased. the flash command erase page and write the lock (ewpl) combines ewp and wpl commands. 23.3.5.3 flash full erase command this command is used to erase the flash memory planes. all lock regions must be unlocked before the full erase command by using the clb command. otherwise, the erase command is aborted and no page is erased. 23.3.5.4 flash lock commands lock bits can be set using wpl or ewpl commands. they can also be set by using the set lock command (slb) . with this command, several lock bits can be activated. a bit mask is provided as argument to the command. when bit 0 of the bit mask is set, then the first lock bit is activated. table 23-7. write command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde wp or wpl or ewp or ewpl 2 write handshaking addr0 memory address lsb 3 write handshaking addr1 memory address 4 write handshaking data *memory address++ 5 write handshaking data *memory address++ ... ... ... ... n write handshaking addr0 memory address lsb n+1 write handshaking addr1 memory address n+2 write handshaking data *memory address++ n+3 write handshaking data *memory address++ ... ... ... ... table 23-8. full erase command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde ea 2 write handshaking data 0
377 sam4cp [datasheet] 43051e?atpl?08/14 in the same way, the clear lock command (clb) is used to clear lock bits. lock bits can be read using get lock bit command (glb). the n th lock bit is active when the bit n of the bit mask is set. 23.3.5.5 flash general-purpose nvm commands general-purpose nvm bits (gp nvm bits) can be set using the set gpnvm command (sgpb). this command also activates gp nvm bits. a bit mask is provided as argument to the command. when bit 0 of the bit mask is set, then the first gp nvm bit is activated. in the same way, the clear gpnvm command (cgpb) is used to clear general-purpose nvm bits. the general-purpose nvm bit is deactivated when the corresponding bit in the pattern value is set to 1. general-purpose nvm bits can be read using the get gpnvm bit command (ggpb) . the n th gp nvm bit is active when bit n of the bit mask is set. 23.3.5.6 flash security bit command a security bit can be set using the set security bit command (sse). once the security bit is active, the fast flash programming is disabled. no other command can be run. an event on the erase pin can erase the security bit once the contents of the flash have been erased. once the security bit is set, it is not possible to access ffpi. the only way to erase the security bit is to erase the flash. table 23-9. set and clear lock bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde slb or clb 2 write handshaking data bit mask table 23-10. get lock bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde glb 2 read handshaking data lock bit mask status 0 = lock bit is cleared 1 = lock bit is set table 23-11. set/clear gp nvm command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde sgpb or cgpb 2 write handshaking data gp nvm bit pattern value table 23-12. get gp nvm bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde ggpb 2 read handshaking data gp nvm bit mask status 0 = gp nvm bit is cleared 1 = gp nvm bit is set table 23-13. set security bit command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde sse 2 write handshaking data 0
378 sam4cp [datasheet] 43051e?atpl?08/14 in order to erase the flash, the user must perform the following: ? power-off the chip ? power-on the chip with tst = 0 ? assert erase during a period of more than 220 ms ? power-off the chip then it is possible to return to ffpi mode and check that flash is erased. 23.3.5.7 memory write command this command is used to perform a write access to any memory location. the memory write command (wram) is optimized for consecutive writes. write handshaking can be chained; an internal address buffer is automatically increased. 23.3.5.8 get version command the get version (gve) command retrieves the version of the ffpi interface. table 23-14. write command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde wram 2 write handshaking addr0 memory address lsb 3 write handshaking addr1 memory address 4 write handshaking data *memory address++ 5 write handshaking data *memory address++ ... ... ... ... n write handshaking addr0 memory address lsb n+1 write handshaking addr1 memory address n+2 write handshaking data *memory address++ n+3 write handshaking data *memory address++ ... ... ... ... table 23-15. get version command step handshake sequence mode[3:0] data[15:0] 1 write handshaking cmde gve 2 read handshaking data version
379 sam4cp [datasheet] 43051e?atpl?08/14 24. cortex m cache controller (cmcc) 24.1 description the cortex m cache controller (cmcc) is a 4-way set associat ive unified cache controller. it integrates a controller, a tag directory, data memory, metadata memory and a configuration interface. 24.2 embedded characteristics ? physically addressed and physically tagged ? l1 data cache set to 2 kbytes ? l1 cache line size set to 16 bytes ? l1 cache integrates 32-bit bus master interface ? unified direct mapped cache architecture ? unified 4-way set associative cache architecture ? write through cache operations, read allocate ? round robin victim selection policy ? event monitoring, with one programmable 32-bit counter ? configuration registers accessible through cortex m private peripheral bus ? cache interface includes cache maintenance operations registers 24.3 block diagram figure 24-1. block diagram cache controller metadata ram data ram tag ram ram interface cortex m interface memory interface registers interface apb interface cortex m memory interface bus system memory bus
380 sam4cp [datasheet] 43051e?atpl?08/14 24.4 functional description 24.4.1 cache operation on reset, the cache controller data entries are all invalidated and the cache is enabled. the cache is transparent to processor operations. the cache controller is activated with its configuration registers. the configuration interface is memory mapped in the private peripheral bus. the cache must always be enabled, even if the code is running out of a non-cached region. when the cache is disabled, the accesses to the cache on its slave port are ?forwarded? to the master port. in this case, there are two simultaneous accesses on the matrix: one on a non-cached region, and another ?dummy? access on the cache master port. these two accesses can slow down the system due to the wait error introduction on the cache master port. 24.4.2 cache maintenance if the contents seen by the cache has changed, the user needs to invalidate the cache entries. it can be done line by line or for all cache entries. 24.4.2.1 cache invalidate by line operation when an invalidate by line command is issued the cache controller resets the valid bit information of the decoded cache line. as the line is no longer valid the replacement counter points to that line. use the following sequence to invalidate one line of cache. 1. disable the cache controller, writing 0 to the cen bit of the control register (cmcc_ctrl). 2. check csts bit of the cmcc_sr to verify that the cache is successfully disabled. 3. perform an invalidate by line writing the bit set {index, way} in the maintenance register 1 (cmcc_maint1). 4. enable the cache controller, writing 1 to the cen bit of the cmcc_ctrl register. 24.4.2.2 cache invalidate all operation to invalidate all cache entries, write a 1 to the invall bit of the maintenance register 0 (cmcc_maint0) 24.4.3 cache performance monitoring the cortex m cache controller includes a programmable 32-bit monitor counter. the monitor can be configured to count the number of clock cycles, the number of data hits or the number of instruction hits. use the following sequence to activate the counter 1. configure the monitor counter, writing the mode field of the monitor configuration register (cmcc_mcfg). 2. enable the counter, writing one to the menable bit of the monitor enable register (cmcc_men). 3. if required, reset the counter, writing one to the swrst bit of the monitor control register (cmcc_mctrl). 4. check the value of the monitor counter, reading event_cnt field of the cmcc_sr.
381 sam4cp [datasheet] 43051e?atpl?08/14 24.5 cortex m cache controller (cmcc) user interface table 24-1. register mapping offset register name access reset 0x00 cache controller type register cmcc_type read-only 0x000011d7 0x04 reserved ? ? ? 0x08 cache controller control register cmcc_ctrl write-only ? 0x0c cache controller status register cmcc_sr read-only 0x00000001 0x10 - 0x1c reserved ? ? ? 0x20 cache controller maintenance register 0 cmcc_maint0 write-only ? 0x24 cache controller maintenance register 1 cmcc_maint1 write-only ? 0x28 cache controller monitor configuration register cmcc_mcfg read/write 0x00000000 0x2c cache controller monitor enable register cmcc_men read/write 0x00000000 0x30 cache controller monitor control register cmcc_mctrl write-only ? 0x34 cache controller monitor status register cmcc_msr read-only 0x00000000 0x38 - 0xfc reserved ? ? ?
382 sam4cp [datasheet] 43051e?atpl?08/14 24.5.1 cache controller type register name: cmcc_type address: 0x4007c000 (0), 0x48018000 (1) access: read-only ? randp: random selection policy supported 0: random victim selection is not supported. 1: random victim selection is supported. ? lrup: least recently used policy supported 0: least recently used policy is not supported. 1: least recently used policy is supported. ? rrp: random selection policy supported 0: random selection policy is not supported. 1: random selection policy is supported. ? waynum: number of ways ? lckdown: lock down supported 0: lock down is not supported. 1: lock down is supported. ? csize: data cache size 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? clsize csize 76543210 lckdown waynum rrp lrup randp ? ? value name description 0 dmapped direct mapped cache 1 arch2way 2-way set associative 2 arch4way 4-way set associative 3 arch8way 8-way set associative value name description 0 csize_1kb data cache size 1 kbyte 1 csize_2kb data cache size 2 kbytes 2 csize_4kb data cache size 4 kbytes 3 csize_8kb data cache size 8 kbytes
383 sam4cp [datasheet] 43051e?atpl?08/14 ? clsize: cache line size value name description 0 clsize_1kb cache line size 4 bytes 1 clsize_2kb cache line size 8 bytes 2 clsize_4kb cache line size 16 bytes 3 clsize_8kb cache line size 32 bytes
384 sam4cp [datasheet] 43051e?atpl?08/14 24.5.2 cache controller control register name: cmcc_ctrl address: 0x4007c008 (0), 0x48018008 (1) access: write-only ? cen: cache controller enable 0: when set to 0, this bit disables the cache controller. 1: when set to 1, this bit enables the cache controller. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????cen
385 sam4cp [datasheet] 43051e?atpl?08/14 24.5.3 cache controller status register name: cmcc_sr address: 0x4007c00c (0), 0x4801800c (1) access: read-only ? csts: cache controller status 0: when read as 0, this bit indicates that the cache controller is disabled. 1: when read as 1, this bit indicates that the cache controller is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????? csts
386 sam4cp [datasheet] 43051e?atpl?08/14 24.5.4 cache controller maintenance register 0 name: cmcc_maint0 address: 0x4007c020 (0), 0x48018020 (1) access: write-only ? invall: cache controller invalidate all 0: no effect. 1: when set to 1, this bit invalidates all cache entries. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????invall
387 sam4cp [datasheet] 43051e?atpl?08/14 24.5.5 cache controller maintenance register 1 name: cmcc_maint1 address: 0x4007c024 (0), 0x48018024 (1) access: write-only ? index: invalidate index this field indicates the cache line that is being invalidated. the size of the index field depends on the cache size: ? for 2 kbytes: 5 bits ? for 4 kbytes: 6 bits ? for 8 kbytes: 7 bits, and so on ? way: invalidate way 31 30 29 28 27 26 25 24 way ?????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ??????? index 76543210 index ???? value name description 0 way0 way 0 is selection for index invalidation 1 way1 way 1 is selection for index invalidation 2 way2 way 2 is selection for index invalidation 3 way3 way 3 is selection for index invalidation
388 sam4cp [datasheet] 43051e?atpl?08/14 24.5.6 cache controller monitor configuration register name: cmcc_mcfg address: 0x4007c028 (0), 0x48018028 (1) access: read/write ? mode: cache controller monitor counter mode 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ? mode value name description 0 cycle_count cycle counter 1 ihit_count instruction hit counter 2 dhit_count data hit counter
389 sam4cp [datasheet] 43051e?atpl?08/14 24.5.7 cache controller monitor enable register name: cmcc_men address: 0x4007c02c (0), 0x4801802c (1) access: read/write ? menable: cache controller monitor enable 0: when set to 0, the monitor counter is disabled. 1: when set to 1, the monitor counter is activated. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????? menable
390 sam4cp [datasheet] 43051e?atpl?08/14 24.5.8 cache controller monitor control register name: cmcc_mctrl address: 0x4007c030 (0), 0x48018030 (1) access: write-only ? swrst: monitor 0: no effect. 1: when set to 1, this bit resets the event counter register. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????? swrst
391 sam4cp [datasheet] 43051e?atpl?08/14 24.5.9 cache controller monitor status register name: cmcc_msr address: 0x4007c034 (0), 0x48018034 (1) access: read-only ? event_cnt: monitor event counter 31 30 29 28 27 26 25 24 event_cnt 23 22 21 20 19 18 17 16 event_cnt 15 14 13 12 11 10 9 8 event_cnt 76543210 event_cnt
392 sam4cp [datasheet] 43051e?atpl?08/14 25. interprocessor communication (ipc) 25.1 description the interprocessor communication (ipc) module has 32 interrupt sources. each source has a set of enable, disable, clear, set, mask and status registers. the interrupt sources are ored, and the ipc interrupt output line is connected to the interrupt controller input. 25.2 block diagram figure 25-1. ipc block diagram figure 25-2. dual core ipc implementation apb arm core ipc_ipr irq0 ipc_ipr irq1 ipc_ipr irq31 thirty-two sources irqn ipc nvic1 nvic0 ipc0 ipc1 async ahb-ahb bridge ahb matrix (mx1) ahb to apb bridge 1 ahb matrix (mx0) ahb to apb bridge 0 to nvic1 to nvic0 core 1 coprocessor core (cortex-m4f) core 0 application core (cortex-m4)
393 sam4cp [datasheet] 43051e?atpl?08/14 25.3 product dependencies 25.3.1 power management the interprocessor communication module is not continuously clocked. the ipc interface is clocked through the power management controller (pmc), therefore the programmer must first configure the pmc to enable the ipc clock. 25.3.2 interrupt line the ipc module has an interrupt line connected to the interrupt controller. handling interrupts requires programming the interrupt controller before configuring the ipc. 25.4 functional description 25.4.1 interrupt sources 25.4.1.1 interrupt generation interrupt sources can be individually generated by writing respectively the ipc_iscr and ipc_iccr registers. 25.4.1.2 interrupt source control each interrupt source (irq0 to irq31) can be enabled or disabled by using the command registers: ipc_iecr (interrupt enable command register) and ipc_idcr (interrupt disable command register). this set of registers conducts enabling or disabling of an instruction. the interrupt mask can be read in the ipc_imr register. all ipc interrupts can be enabled/disabled, thus configuring the ipc interrupt mask register. each pending and unmasked ipc interrupt asserts the ipc output interrupt line. a disabled interrupt does not affect servicing of other interrupts. 25.4.1.3 interrupt status the ipc_iecr and ipc_idcr registers are used to determine which interrupt sources are active/inhibited to generate an interrupt output. the ipc_imr register is a status of the interrupt source selection (a result from write into the ipc_iecr and ipc_idcr registers). the ipc_iscr and ipc_iccr registers are used to activate/inhibit interrupt sources. the ipc_ipr register is a status register giving active interrupt sources. the ipc_isr register reports which interrupt source(s) is(are) currently asserting an interrupt output. ipc_isr is basically equivalent to an and between the ipc_ipr and ipc_imr registers. table 25-1. peripheral ids instance id ipc0 31 ipc1 39
394 sam4cp [datasheet] 43051e?atpl?08/14 figure 25-3. interrupt input stage 25.5 inter-processor communication (ipc) user interface clear set interrup t controll er ipc_ipr irq0 ipc_isr irq0 ipc_idcr irq0 ipc_imr irq0 ipc_iecr irq0 ipc_iccr irq0 ipc_iscr irq0 clear set clear set ipc_ipr irq31 ipc_isr irq31 ipc_idcr irq31 ipc_imr irq31 ipc_iecr irq31 ipc_iccr irq31 ipc_iscr irq31 clear set table 25-2. register mapping offset register name access reset 0x0000 interrupt set command register ipc_iscr write-only ? 0x0004 interrupt clear command register ipc_iccr write-only ? 0x0008 interrupt pending register ipc_ipr read-only 0x0 0x000c interrupt enable command register ipc_iecr write-only ? 0x0010 interrupt disable command register ipc_idcr write-only ? 0x0014 interrupt mask register ipc_imr read-only 0x0 0x0018 interrupt status register ipc_isr read-only 0x0
395 sam4cp [datasheet] 43051e?atpl?08/14 25.5.1 ipc interrupt set command register name: ipc_iscr address: 0x4004c000 (0), 0x48014000 (1) access: write-only ? irq0-irq31: interrupt set 0: no effect. 1: sets the corresponding interrupt. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
396 sam4cp [datasheet] 43051e?atpl?08/14 25.5.2 ipc interrupt clear command register name: ipc_iccr address: 0x4004c004 (0), 0x48014004 (1) access: write-only ? irq0-irq31: interrupt clear 0: no effect. 1: clears the corresponding interrupt. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
397 sam4cp [datasheet] 43051e?atpl?08/14 25.5.3 ipc interrupt pending register name: ipc_ipr address: 0x4004c008 (0), 0x48014008 (1) access: read-only reset: 0x0 ? irq0-irq31: interrupt pending 0: the corresponding interrupt is not pending. 1: the corresponding interrupt is pending. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
398 sam4cp [datasheet] 43051e?atpl?08/14 25.5.4 ipc interrupt enable command register name: ipc_iecr address: 0x4004c00c (0), 0x4801400c (1) access: write-only ? irq0-irq31: interrupt enable 0: no effect. 1: enables the corresponding interrupt. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
399 sam4cp [datasheet] 43051e?atpl?08/14 25.5.5 ipc interrupt disable command register name: ipc_idcr address: 0x4004c010 (0), 0x48014010 (1) access: write-only ? irq0-irq31: interrupt disable 0: no effect. 1: disables the corresponding interrupt. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
400 sam4cp [datasheet] 43051e?atpl?08/14 25.5.6 ipc interrupt mask register name: ipc_imr address: 0x4004c014 (0), 0x48014014 (1) access: read-only reset: 0x0 ? irq0-irq31: interrupt mask 0: the corresponding interrupt is disabled. 1: the corresponding interrupt is enabled. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
401 sam4cp [datasheet] 43051e?atpl?08/14 25.5.7 ipc interrupt status register name: ipc_isr access: read-only reset: 0x0 ? irq0-irq31: current interrupt identifier 0: the corresponding interrupt source is not currently asserting the interrupt output. 1: the corresponding interrupt source is currently asserting the interrupt output. 31 30 29 28 27 26 25 24 irq31 irq30 irq29 irq28 irq27 irq26 irq25 irq24 23 22 21 20 19 18 17 16 irq23 irq22 irq21 irq20 irq19 irq18 irq17 irq16 15 14 13 12 11 10 9 8 irq15 irq14 irq13 irq12 irq11 irq10 irq9 irq8 76543210 irq7 irq6 irq5 irq4 irq3 irq2 irq1 irq0
402 sam4cp [datasheet] 43051e?atpl?08/14 26. bus matrix (matrix) 26.1 description the bus matrix implements a multi-layer ahb, based on the ahb-lite protocol, that enables parallel access paths between multiple ahb masters and slaves in a system, thus increasing the overall bandwidth. the bus matrix interconnects ahb masters to ahb slaves. the normal latency to connect a master to a slave is one cycle except for the default master of the accessed slave which is connected directly (zero cycle latency). 26.2 embedded characteristics ? one decoder for each master. ? support for long bursts of 32, 64, 128 beats and up to the 256-beat word burst ahb limit. ? enhanced programmable mixed arbitration for each slave. ? round-robin. ? fixed priority. ? latency quality of service. ? programmable default master for each slave. ? no default master. ? last accessed default master. ? fixed default master. ? deterministic maximum access latency for masters. ? zero or one cycle arbitration latency for the first access of a burst. ? bus lock forwarding to slaves. ? master number forwarding to slaves. ? write protection of user interface registers. 26.2.1 matrix 0 26.2.1.1 matrix 0 masters the bus matrix 0, which corresponds to the sub-system 0 (core 0 - cm4p0) manages the masters listed in table 26-1 . each master can perform an access to an available slave concurrently with other masters. each master has its own specifically-defined decoder. in order to simplify the addressing, all the masters have the same decodings. table 26-1. list of bus matrix masters master 0 cortex-m4 instruction/data (cm4p0 i/d bus) master 1 cortex-m4 system (cm4p0 s bus) master 2 peripheral dma controller 0 (pdc0) master 3 integrity check module (icm) master 4 matrix1 master 5 reserved master 6 cmcc0
403 sam4cp [datasheet] 43051e?atpl?08/14 26.2.1.2 matrix 0 slaves the bus matrix of the sam4cp manages the slaves listed in table 26-2 . each slave has its own arbiter providing a dedicated arbitration per slave. 26.2.1.3 master to slave access (matrix 0) table 26-3 gives valid paths for master to slave access on matrix 0. the paths shown as ?-? are forbidden or not wired, e.g. access from the cortex-m4 s bus to the internal rom. 26.2.1.4 accesses through matrix 0 ? cm4p0 i/d bus access to: ? flash, rom ? flash through cache controller cmcc0 (respectively through 0x11000000 to 0x11ffffff and 0x13000000 to 0x16ffffff) ? cmp4p0 s bus access to: ? sram0, sram1 through matrix1, sram2 through matrix1 ? cpkcc table 26-2. list of bus matrix slaves slave 0 internal sram0 slave 1 internal rom slave 2 internal flash slave 3 reserved slave 4 peripheral bridge 0 slave 5 cpkcc ram and rom slave 6 matrix1 slave 7 cmcc0 table 26-3. matrix 0 master to slave access slaves masters 0 1 2 3 4 5 6 cortex-m4 i/d bus cortex-m4 s bus pdc0 icm matrix1 reserved cmcc0 0 internal sram0 - x x x x - - 1 internal rom x - x x - - - 2 internal flash x - - x x - x 3 reserved - - - - - - - 4 peripheral bridge 0 - x x - x - - 5 cpkcc sram, rom - x - x - - - 6 matrix1 - x - x - - - 7 cmcc0 x - - - - - -
404 sam4cp [datasheet] 43051e?atpl?08/14 ? pdc0 access to: ? sram0, rom ? hbridge0 ? icm access to: ? flash, rom, sram0, sram1 through matrix1, sram2 through matrix1 ? cpkcc ? hbridge1 through matrix1 ? matrix1 access to ? flash through 0x01000000 to 0x01ffffff and 0x11000000 to 0x11ffffff) ? sram0 ? hbridge0 ? cache controller cmcc0 access to: ? flash (through 0x11000000 to 0x11ffffff) 26.2.2 matrix 1 26.2.2.1 matrix 1 masters the bus matrix 1, which corresponds to the sub-system 1 (core 1 - cm4p1), manages the masters listed in table 26-4 . each master can perform an access to an available slave concurrently with other masters. each master has its own specifically-defined decoder. in order to simplify the addressing, all the masters have the same decodings. 26.2.2.2 matrix 1 slaves the bus matrix of the sam4cp manages the slaves listed in table 26-5 . each slave has its own arbiter providing a dedicated arbitration per slave. table 26-4. list of bus matrix masters master 0 cortex-m4 instruction/data (cm4p1 i/d bus) master 1 cortex-m4 system (cm4p1 s bus) master 2 peripheral dma controller 1 (pdc1) master 3 matrix0 master 4 reserved master 5 cmcc1 table 26-5. list of bus matrix slaves slave 0 internal sram1 slave 1 internal sram2 slave 2 reserved slave 3 peripheral bridge 1 slave 4 matrix0 slave 5 cmcc1
405 sam4cp [datasheet] 43051e?atpl?08/14 26.2.2.3 master to slave access (matrix 1) table 26-6 gives valid paths for master to slave access on matrix 1. the paths shown as ?-? are forbidden or not wired, e.g. access from the cortex-m4 s bus to the internal rom. 26.2.2.4 accesses through matrix 1 ? cm4p1 i/d bus access to: ? flash (through 0x01000000 to 0x01ffffff) ? flash through cache cmcc1 ? cm4p1 s-bus access to: ? sram1, sram2, sram0 through matrix0 (0x20000000) ? hbridge1, hbridge0 through matrix0 (0x40000000) ? pdc1 access to: ? sram1, sram2 ? hbridge1 ? matrix0 access to: ? sram1, sram2 ? hbridge1 ? cache cmcc1 access to: ? flash through 0x11000000 table 26-6. matrix 1 master to slave access slaves masters 0 1 2 3 4 5 cortex-m4 i/d bus cortex-m4 s bus pdc1 matrix0 reserved cmcc1 0 internal sram1 x x x x - - 1 internal sram2 - x x x - - 2 reserved - - - - - - 3 peripheral bridge 1 - x x x - - 4 matrix0 x x - - - x 5 cmcc1 x - - - - -
406 sam4cp [datasheet] 43051e?atpl?08/14 26.3 special bus granting mechanism the bus matrix provides some speculative bus granting techniques in order to anticipate access requests from masters. this mechanism reduces latency at first access of a burst, or for a single transfer, as long as the slave is free from any other master access. however, the technique does not provide any benefit if the slave is continuously accessed by more than one master, since arbitration is pipelined and has no negative effect on the slave bandwidth or access latency. this bus granting mechanism sets a different default master for every slave. at the end of the current access, if no other request is pending, the slave remains connected to its associated default master. a slave can be associated with three kinds of default masters: ? no default master ? last access master ? fixed default master to change from one type of default master to another, the bus matrix user interface provides slave configuration registers, one for every slave which se t a default master for each slave. the slave configuration register contains two fields to manage master selection: defmstr_type and fixed_defmstr. the 2-bit defmstr_type field selects the default master type (no default, last access master, fixed default master), whereas the 4-bit fixed_defmstr field selects a fixed default master provided that defmstr_type is set to fixed default master. refer to section 26.9.2 ?bus matrix slave configuration registers? on page 413 . 26.4 no default master after the end of the current access, if no other request is pending, the slave is disconnected from all masters. this configuration incurs one latency clock cycle for the first access of a burst after bus idle. arbitration without the default master may be used for masters that perform significant bursts or several transfers with no idle in between, or if the slave bus bandwidth is widely used by one or more masters. this configuration provides no benefit on access latency or bandwidth when reaching maximum slave bus throughput regardless of the number of requesting masters. 26.5 last access master after the end of the current access, if no other request is pending, the slave rema ins connected to the last master that performed an access request. this allows the bus matrix to remove the one latency cycle for the last master that accessed the slave. other non privileged masters still get one latency clock cycle if they need to access the same slave. this technique is used for masters that perform single accesses or short bursts with some idle cycles in between. this configuration provides no benefit on access latency or bandwidth when reaching maximum slave bus throughput whatever is the number of requesting masters. 26.6 fixed default master after the end of the current access, if no other request is pe nding, the slave connects to its fixed default master. unlike the last access master, the fixed default master does not change unless the user modifies it by software (fixed_defmstr field of the related matrix_scfg). this allows the bus matrix arbiters to remove the one latency clock cycle for the fixed default master of the slave. all requests attempted by the fixed default master do not cause any arbitration latency, whereas other non-privileged masters will get one latency cycle. this technique is used for a master that mainly performs single accesses or short bursts with idle cycles in between. this configuration provides no benefit on access latency or bandwidth when reaching maximum slave bus throughput, regardless of the number of requesting masters.
407 sam4cp [datasheet] 43051e?atpl?08/14 26.7 arbitration the bus matrix provides an arbitration mechanism that reduces latency when conflict occurs, i.e. when two or more masters try to access the same slave at the same time. one arbiter per ahb slave is provided, thus arbitrating each slave specifically. the bus matrix provides the user with the possibility of choosing between two arbitration types or mixing them for each slave: 1. round-robin arbitration (default) 2. fixed priority arbitration the resulting algorithm may be complemented by selecting a default master configuration for each slave. when re-arbitration must be done, specific conditions apply. see section 26.7.1 ?arbitration scheduling? on page 407 . 26.7.1 arbitration scheduling each arbiter has the ability to arbitrate between two or more master requests. in order to avoid burst breaking and also to provide the maximum throughput for slave interfaces, arbitration may only take place during the following cycles: 1. idle cycles: when a slave is not connected to any master or is connected to a master which is not currently accessing it. 2. single cycles: when a slave is currently doing a single access. 3. end of burst cycles: when the current cycle is the last cycle of a burst transfer. for defined burst length, predicted end of burst matches the size of the transfer but is managed differently for undefined burst length. see ?undefined length burst arbitration? on page 407 . 4. slot cycle limit: when the slot cycle counter has reached the limit value, indicating that the current master access is too long and must be broken. see ?slot cycle limit arbitration? on page 408 . 26.7.1.1 undefined length burst arbitration in order to prevent long ahb burst lengths that can lock the access to the slave for an excessive period of time, the user can trigger the re-arbitration before the end of the incremental bursts. the re-arbitration period can be selected from the following undefined length burst type (ulbt) possibilities: 1. unlimited: no predetermined end of burst is generated. this value enables 1-kbyte burst lengths. 2. 1-beat bursts: predetermined end of burst is generated at each single transfer during the incr transfer. 3. 4-beat bursts: predetermined end of burst is generated at the end of each 4-beat boundary during incr transfer. 4. 8-beat bursts: predetermined end of burst is generated at the end of each 8-beat boundary during incr transfer. 5. 16-beat bursts: predetermined end of burst is generated at the end of each 16-beat boundary during incr transfer. 6. 32-beat bursts: predetermined end of burst is generated at the end of each 32-beat boundary during incr transfer. 7. 64-beat bursts: predetermined end of burst is generated at the end of each 64-beat boundary during incr transfer. 8. 128-beat bursts: predetermined end of burst is generated at the end of each 128-beat boundary during incr transfer. the use of undefined length 8-beat bursts or less is discouraged since this may decrease the overall bus bandwidth due to arbitration and slave latencies at each first access of a burst. however, if the usual length of undefined length bursts is known for a master, it is recommended to configure the ulbt according to this length. this selection can be done through the ulbt field of the master configuration registers (matrix_mcfg).
408 sam4cp [datasheet] 43051e?atpl?08/14 26.7.1.2 slot cycle limit arbitration the bus matrix contains specific logic to break long accesses, such as very long bursts on a very slow slave (e.g., an external low speed memory). at each arbitration time, a counter is loaded with the value previously written in the slot_cycle field of the related slave configuration register (matrix_scfg) and decreased at each clock cycle. when the counter elapses, the arbiter has the ability to re-arbitrate at the end of the current ahb bus access cycle. unless a master has a very tight access latency constraint, which could lead to data overflow or underflow due to a badly undersized internal fifo with respect to its throughput, the sl ot cycle limit should be disabled (slot_cycle = 0) or set to its default maximum value in order not to inefficiently break long bursts performed by some atmel masters. in most cases, this feature is not needed and should be disabled for power saving. warning: this feature cannot prevent any slave from locking its access indefinitely. 26.7.2 arbitration priority scheme the bus matrix arbitration scheme is organized in priority pools. the corresponding access criticality class is assigned to each priority pool as shown in the ?latency quality of service? column in table 26-7 . latency quality of service is determined through the bus matrix user interface. see section 26.9.3 ?bus matrix priority registers a for slaves? for details. round-robin priority is used in the highest and lowest priority pools 3 and 0, whereas fixed level priority is used between priority pools and in the intermediate priority pools 2 and 1. see section 26.7.2.2 ?round-robin arbitration? . for each slave, each master is assigned to one of the slave priority pools through the latency quality of service inputs or through the priority registers for slaves (mxpr fields of matrix_pras and matrix_prbs). when evaluating master requests, this priority pool level always takes precedence. after reset, most of the masters belong to the lowest priori ty pool (mxpr = 0, background transfer) and, therefore, are granted bus access in a true round-robin order. the highest priority pool must be specifically reserved for masters requiring very low access latency. if more than one master belongs to this pool, they will be granted bus access in a biased round-robin manner which allows tight and deterministic maximum access latency from ahb bus requests. in the worst case, any currently occurring high-priority master request will be granted after the current bus master access has ended and other high priority pool master requests, if any, have been granted once each. the lowest priority pool shares the remaining bus bandwidth between ahb masters. intermediate priority pools allow fine priority tuning. typically, a latency-sensitive master or a bandwidth-sensitive master will use such a priority level. the higher the priority level (mxpr value), the higher the master priority. for good cpu performance, it is recommended to configure cpu priority with the default reset value 2 (latency sensitive). all combinations of mxpr values are allowed for all masters and slaves. for example, some masters might be assigned the highest priority pool (round-robin), and remaining masters the lowest priority pool (round-robin), with no master for intermediate fix priority levels. table 26-7. arbitration priority pools priority pool latency quality of service 3 latency critical 2 latency sensitive 1 bandwidth sensitive 0 background transfers
409 sam4cp [datasheet] 43051e?atpl?08/14 26.7.2.1 fixed priority arbitration fixed priority arbitration algorithm is the first and only arbitration algorithm applied between masters from distinct priority pools. it is also used in priority pools other than the highest and lowest priority pools (intermediate priority pools). fixed priority arbitration allows the bus matrix arbiters to dispatch the requests from different masters to the same slave by using the fixed priority defined by the user in the mxpr field for each master in the priority registers, matrix_pras and matrix_prbs. if two or more master requests are active at the same time, the master with the highest priority mxpr number is serviced first. in intermediate priority pools, if two or more master requests with the same priority are active at the same time, the master with the highest number is serviced first. 26.7.2.2 round-robin arbitration this algorithm is only used in the highest and lowest priority pools. it allows the bus matrix arbiters to properly dispatch requests from different masters to the same slave. if two or more master requests are active at the same time in the priority pool, they are serviced in a round-robin increasing master number order. 26.8 register write protection to prevent any single software error from corrupting the bus matrix behavior, certain registers in the address space can be write-protected by setting the wpen bit in the ?write protection mode register? (matrix_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the ?write protection status register? (matrix_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the matrix_wpsr. the following registers can be write-protected: ? ?bus matrix master configuration registers? ? ?bus matrix slave configuration registers? ? ?bus matrix priority registers a for slaves? ? ?system i/o configuration register?
410 sam4cp [datasheet] 43051e?atpl?08/14 26.9 ahb bus matrix (matrix) user interface table 26-8. register mapping offset register name access reset 0x0000 master configuration register 0 matrix_mcfg0 read/write 0x00000004 0x0004 master configuration register 1 matrix_mcfg1 read/write 0x00000004 0x0008 master configuration register 2 matrix_mcfg2 read/write 0x00000004 0x000c master configuration register 3 matrix_mcfg3 read/write 0x00000004 0x0010 master configuration register 4 matrix_mcfg4 read/write 0x00000004 0x0014 master configuration register 5 matrix_mcfg5 read/write 0x00000004 0x0018 master configuration register 6 matrix_mcfg6 read/write 0x00000004 0x001c - 0x003c reserved ? ? ? 0x0040 slave configuration register 0 matrix_scfg0 read/write 0x000001ff 0x0044 slave configuration register 1 matrix_scfg1 read/write 0x000001ff 0x0048 slave configuration register 2 matrix_scfg2 read/write 0x000001ff 0x004c slave configuration register 3 matrix_scfg3 read/write 0x000001ff 0x0050 slave configuration register 4 matrix_scfg4 read/write 0x000001ff 0x0054 slave configuration register 5 matrix_scfg5 read/write 0x000001ff 0x0058 slave configuration register 6 matrix_scfg6 read/write 0x000001ff 0x005c slave configuration register 7 matrix_scfg7 read/write 0x000001ff 0x0060 - 0x007c reserved ? ? ? 0x0080 priority register a for slave 0 matrix_pras0 read/write 0x00000000 (1) 0x0084 reserved ? ? ? 0x0088 priority register a for slave 1 matrix_pras1 read/write 0x00000000 (1) 0x008c reserved ? ? ? 0x0090 priority register a for slave 2 matrix_pras2 read/write 0x00000000 (1) 0x0094 reserved ? ? ? 0x0098 priority register a for slave 3 matrix_pras3 read/write 0x00000000 (1) 0x009c reserved ? ? ? 0x00a0 priority register a for slave 4 matrix_pras4 read/write 0x00000000 (1) 0x00a4 reserved ? ? ? 0x00a8 priority register a for slave 5 matrix_pras5 read/write 0x00000000 (1) 0x00ac reserved ? ? ? 0x00b0 priority register a for slave 6 matrix_pras6 read/write 0x00000000 (1) 0x00b4 reserved ? ? ? 0x00b8 priority register a for slave 7 matrix_pras7 read/write 0x00000000 (1) 0x00bc - 0x0110 reserved ? ? ? 0x0114 system i/o configuration register matrix_sysio read/write 0x00000000 0x0118 reserved ? ? ?
411 sam4cp [datasheet] 43051e?atpl?08/14 note: 1. values in the bus matrix priority registers are product dependent. 0x0120 reserved ? ? ? 0x0124 reserved ? ? ? 0x0128 core debug configuration register matrix_core_debug read/write 0x00000000 0x012c - 0x01e0 reserved ? ? ? 0x01e4 write protection mode register matrix_wpmr read/write 0x00000000 0x01e8 write protection status register matrix_wpsr read-only 0x00000000 table 26-8. register mapping (continued) offset register name access reset
412 sam4cp [datasheet] 43051e?atpl?08/14 26.9.1 bus matrix master configuration registers name: matrix_mcfgx [x=0..6] address: 0x400e0200 (0), 0x48010000 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?write protection mode register? . ? ulbt: undefined length burst type 0: unlimited length burst no predicted end of burst is generated, therefore incr bursts coming from this master can only be broken if the slave slot cycl e limit is reached. if the slot c ycle limit is not reached, the burst is normally completed by the master, at the latest, on the next ahb 1 kbyte address boundary, allowing up to 256-beat word bursts or 128-beat double-word bursts. this value should not be used in the very particular case of a master capable of performing back-to-back undefined length burst s on a single slave, since this could indefinitely freeze the slave arbitration and thus prevent another master from accessing th is slave. 1: single access the undefined length burst is treated as a succession of single accesses, allowing re-arbitration at each beat of the incr burs t or bursts sequence. 2: 4-beat burst the undefined length burst or bursts sequence is split into 4-beat bursts or less, allowing re-arbitration every 4 beats. 3: 8-beat burst the undefined length burst or bursts sequence is split into 8-beat bursts or less, allowing re-arbitration every 8 beats. 4: 16-beat burst the undefined length burst or bursts sequence is split into 16-beat bursts or less, allowing re-arbitration every 16 beats. 5: 32-beat burst the undefined length burst or bursts sequence is split into 32-beat bursts or less, allowing re-arbitration every 32 beats. 6: 64-beat burst the undefined length burst or bursts sequence is split into 64-beat bursts or less, allowing re-arbitration every 64 beats. 7: 128-beat burst the undefined length burst or bursts sequence is split into 128-beat bursts or less, allowing re-arbitration every 128 beats. unless duly needed, the ulbt should be left at its default 0 value for power saving. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ulbt
413 sam4cp [datasheet] 43051e?atpl?08/14 26.9.2 bus matrix slave configuration registers name: matrix_scfgx [x=0..7] address: 0x400e0240 (0), 0x48010040 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?write protection mode register? . ? slot_cycle: maximum bus grant duration for masters when slot_cycle ahb clock cycles have elapsed since the last arbitration, a new arbitration takes place to let another master access this slave. if another master is requesting the slave bus, then the current master burst is broken. if slot_cycle = 0, the slot cycle limit feature is disabled and bursts always complete unless broken according to the ulbt. this limit has been placed in order to enforce arbitration so as to meet potential latency constraints of masters waiting for s lave access. this limit must not be too small. unreas onably small values break every burst and the bus matrix arbitrates without performing any data transfer. the default maximum value is usually an optimal conservative choice. in most cases, this feature is not needed and should be disabled for power saving. see section 26.7.1.2 ?slot cycle limit arbitration? for details. ? defmstr_type: default master type 0: no default master at the end of the current slave access, if no other master request is pending, the slave is disconnected from all masters. this results in a one clock cycle latency for the first access of a burst transfer or for a single access. 1: last default master at the end of the current slave access, if no other master request is pending, the slave stays connected to the last master hav ing accessed it. this results in not having one clock cycle latency when the last master tries to access the slave again. 2: fixed default master at the end of the current slave access, if no other master request is pending, the slave connects to the fixed master the numbe r that has been written in the fixed_defmstr field. this results in not having one clock cycle latency when the fixed master tries to access the slave again. ? fixed_defmstr: fixed default master this is the number of the default master for this slave. only used if defmstr_type is 2. specifying the number of a master which is not connected to the selected slave is equivalent to setting defmstr_type to 0. 31 30 29 28 27 26 25 24 ??????? ? 23 22 21 20 19 18 17 16 ? ? fixed_defmstr defmstr_type 15 14 13 12 11 10 9 8 ? ? ? ? ? ? ? slot_cycle 7654321 0 slot_cycle
414 sam4cp [datasheet] 43051e?atpl?08/14 26.9.3 bus matrix priority registers a for slaves name: matrix_prasx [x=0..7] address: 0x400e0280 (0)[0], 0x400e0288 (0)[1], 0x400e0290 (0)[2], 0x400e0298 (0)[3], 0x400e02a0 (0)[4], 0x400e02a8 (0)[5], 0x400e02b0 (0)[6], 0x400e02b8 (0)[7], 0x48010080 (1)[0], 0x48010088 (1)[1], 0x48010090 (1)[2], 0x48010098 (1)[3], 0x480100a0 (1)[4], 0x480100a8 (1)[5], 0x480100b0 (1)[6], 0x480100b8 (1)[7] access: read/write this register can only be written if the wpe bit is cleared in the ?write protection mode register? . ? mxpr: master x priority fixed priority of master x for accessing the selected slave. the higher the number, the higher the priority. all the masters programmed with the same mxpr value for the slave make up a priority pool. round-robin arbitration is used in the lowest (mxpr = 0) and highest (mxpr = 3) priority pools. fixed priority is used in intermediate priority pools (mxpr = 1) and (mxpr = 2). see ?arbitration priority scheme? on page 408 for details. 31 30 29 28 27 26 25 24 ? ? m7pr ? ? m6pr 23 22 21 20 19 18 17 16 ? ? m5pr ? ? m4pr 15 14 13 12 11 10 9 8 ? ? m3pr ? ? m2pr 76543210 ? ? m1pr ? ? m0pr
415 sam4cp [datasheet] 43051e?atpl?08/14 26.9.4 system i/o configuration register name: matrix_sysio address: 0x400e0314 (0), 0x48010114 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?write protection mode register? . ? sysio0: pb0 or tdi assignment 0 = tdi function selected. 1 = pb0 function selected. ? sysio1: pb1 or tdo/traceswo assignment 0 = tdo/traceswo function selected. 1 = pb1 function selected. ? sysio2: pb2 or tms/swdio assignment 0 = tms/swdio function selected. 1 = pb2 function selected. ? sysio3: pb3 or tck/swclk assignment 0 = tck/swclk function selected. 1 = pb3 function selected. ? sysio9: pc9 or erase assignment 0 = erase function selected. 1 = pc9 function selected. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?????? sysio9 ? 76543210 ???? sysio3 sysio2 sysio1 sysio0
416 sam4cp [datasheet] 43051e?atpl?08/14 26.9.5 core debug configuration register name: matrix_core_debug address: 0x400e0328 (0), 0x48010128 (1) access: read/write reset: 0x0000_0000 ? cross_trig1: core 1 --> core 0 cross triggering 0 = core 1 is not able to trigger an event on core 0. 1 = core 1 is able to trigger an event on core 0. ? cross_trig0: core 0 --> core 1 cross triggering 0 = core 0 is not able to trigger an event on core 1. 1 = core 0 is able to trigger an event on core 1. 31 30 29 28 27 26 25 24 ????? ? ?? 23 22 21 20 19 18 17 16 ????? ? ?? 15 14 13 12 11 10 9 8 ????? ? ?? 76543 2 10 ? ? ? ? ? cross_trg0 cross_trg1 ?
417 sam4cp [datasheet] 43051e?atpl?08/14 26.9.6 write protection mode register name: matrix_wpmr address: 0x400e03e4 (0), 0x480101e4 (1) access: read/write reset: see table 26-8 for more information on write protection registers, refer to section 26.8 ?register write protection? . ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x4d4154 (?mat? in ascii). 1: enables the write protection if wpkey corresponds to 0x4d4154 (?mat? in ascii). see section 26.8 ?register write protection? for the list of registers that can be protected. ? wpkey: write protection key (write-only) 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x4d4154 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
418 sam4cp [datasheet] 43051e?atpl?08/14 26.9.7 write protection status register name: matrix_wpsr address: 0x400e03e8 (0), 0x480101e8 (1) access: read-only reset: see table 26-8 for more information on write protection registers, refer to section 26.8 ?register write protection? . ? wpvs: write protection violation status 0: no write protection violation has occurred since the last read of the matrix_wpsr register. 1: a write protection violation has occurred since the last read of the matrix_wpsr register. if this violation is an unauthori zed attempt to write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
419 sam4cp [datasheet] 43051e?atpl?08/14 27. prime power line communications (pplc) 27.1 description pplc is a peripheral implementing a prime [power line intelligent metering evolution] plc modem. 27.2 embedded characteristics ? modem ? power line carrier modem for 50 hz and 60 hz mains ? 97-carriers ofdm prime compliant ? dbpsk, dqpsk, d8psk modulation schemes available ? additional enhanced modes available: dbpsk robust, dqpsk robust, named ?prime + robust? in this datasheet ? eight selectable channels between 42khz to 472khz available. only one channel can be active at a time ? baud rate selectable: 5.4 to 128.6 kbps ? four dedicated buffers for transmission/reception ? up to 124.6 db vrms injected signal against prime load ? up to 79.6 db of dynamic range in prime networks ? automatic gain control and continuous amplitude tracking in signal reception ? class d switching power amplifier control ? integrated 1.2v ldo regulator to supply analog functions ? medium access control co-processor features ? viterbi soft decoding and prime crc calculation ? 128-bit aes encryption ? channel sensing and collision pre-detection 41,992 88,867 96,680 143.555 151.367 198,242 206,055 252,930 260,742 307,617 315,430 362,305 370,117 416,992 424,805 471,680 cenelec a - bcd arib fcc channel 1 channel 2 channel 3 channel 4 channel 5 channel 6 channel 7 channel 8 f (khz)
420 sam4cp [datasheet] 43051e?atpl?08/14 27.3 block diagram figure 27-1. pplc functional block diagram adc vima vrp vrm vrc vipa emit(0:5) txrx0 emit(6:11) txrx1 emiter_ctrl agc_ctrl agc(0:5) zero cross detector vz cross ber phy control clock & reset interface arst pll init clkea clkeb srst power management vddpll plc gnd vddin plc vddout plc vddio vddout an clkout transmission chain vddin an phy_core buf_rx2 buf_rx1 txdrv0 recepon chain agnd txdrv1 buf_rx0 buf_tx0 buf_tx1 buf_rx3 buf_tx2 buf_tx3 cd cinr rssi evm crc aes
421 sam4cp [datasheet] 43051e?atpl?08/14 27.4 plc coupling circuitry description all plc coupling reference designs to be used with atmel plc devices have been developed looking for the same designing values: high performance, low cost and simplicity. with these values on mind, atmel has developed a wide range of plc couplings covering frequencies up to 472 khz compliant with different applicable regulations. see table 27-1 below. atmel plc technology is purely digital and does not require external dac/adc, thus simplifying the external required circuitry. generally atmel plc coupling reference designs make use of few passive components plus a class d amplification stage for transmission. 27.4.1 plc coupling sub-circuits all plc coupling reference designs are generally composed by the same sub-circuits: ? transmission stage ? reception stage ? filtering stage ? coupling stage figure 27-2. plc coupling example a particular reference design can contain more than one sub-circuit of the same kind (i.e.: two transmission stages). 27.4.1.1 transmission stage the transmission stage adapts the emit signals and amplifies them if required. it can be composed by: ? driver: a group of resistors which adapt the emit signals to either control the class-d amplifier or to be filtered by the next stage. ? amplifier: if required, a class-d amplifier which generates a square waveform from 0 to v dd is included. ? bias and protection: a couple of resistors and a couple of schottky barrier diodes provide a dc component and provide protection from received disturbances. transmission stage shall be always followed by a filtering stage. agc1 agc0 agc5 agc4 agc3 agc2 vipa vrc vima emit0 emit5 emit4 emit3 emit2 emit1 txrx0 to mains reception stage transmission stage coupling stage sam4cp16b filtering stage v dd
422 sam4cp [datasheet] 43051e?atpl?08/14 27.4.1.2 filtering stage the filtering stage is composed by band-pass filters which have been designed to achieve high performance in field deployments complying at the same time with the proper normative and standards. the in-band flat response filtering stage does not distort the in jected signal, reduces spurious emission to the limits set by the corresponding regulation and blocks potential interferences from other transmission channels. the filtering stage has three aims: ? band-pass filtering of high frequency components of the square waveform generated by the transmission stage. ? adapt input/output impedances for optimal reception/transmission. this is controlled by txrx signal. ? in some cases, band-pass filtering for received signals. when the system is intended to be connected to a physical channel with high voltage or which is not electrically referenced to the same point then the filtering stage must be always followed by a coupling stage. 27.4.1.3 coupling stage the coupling stage blocks the dc component of the line to/from which the signal is injected/received (i.e.: 50/60 hz of the mains). this is carried out by a high voltage capacitor. coupling stage could also electrically isolate the coupling circuitry from the external world by means of a 1:1 transformer. 27.4.1.4 reception stage the reception stage adapts the received analog signal to be properly captured by the pplc internal reception chain. reception circuit is independent of the plc channel which is being used. it basically consists of: ? anti aliasing filter (rc filter) ? automatic gain control (agc) circuit ? driver of the internal adc the agc circuit avoids distortion on the received signal that may arise when the input signal is high enough to polarize the protective diodes in direct region. the driver to the internal adc comprises a couple of resistors and a couple of capacitors. this driver provides a dc component and adapts the received signal to be properly converted by the internal reception chain. 27.4.2 atplcoup boards table 27-1 summarizes the main characteristics of currently available plc coupling reference designs. notes: 1. please refer to atmel doc43052 ?plc coupling reference designs? for a complete description of atplcoup boards. table 27-1. atplcoup boards (1) board name frequency band branch electrical isolation prime channel cenelec band arib fcc atplcoup000 41 - 89 khz double x ch 1 a atplcoup001 41 - 89 khz single x ch 1 a atplcoup002 206 - 417 khz x ch 4, 5, 6, 7 x atplcoup003 41 - 89 khz double ch 1 a atplcoup004 41 - 89 khz single ch 1 a atplcoup005 96 - 144 khz x ch 2 b - c - d atplcoup006 151 - 472 khz double x ch 3, 4, 5, 6, 7, 8 x
423 sam4cp [datasheet] 43051e?atpl?08/14 27.5 signal description table 27-2. signal description signal name function type vima negative differential voltage input input vipa positive differential voltage input input vrp internal reference ?plus? voltage. connect an external decoupling capacitor between vrp and vrm (1nf - 100nf) output vrm internal reference ?minus? voltage. connect an external decoupling capacitor between vrp and vrm (1nf - 100nf) output vrc common-mode voltage. bypass to analog ground with an external decoupling capacitor (100pf - 1nf) output emit0 - emit11 plc transmission ports output agc0 - agc5 plc automatic gain control: ? these digital tri-state outputs are managed by acg hardware logic to drive external circuitry when input signal attenuation is needed output txrx0 - txrx1 plc ext. coupling txrx control output vz cross mains zero-cross detection signal: ? this input detects the zero-crossing of the mains voltage input arst plc asynchronous reset: ? arst is active low ? internal configuration: 33k typ. pull up resistor input srst plc synchronous reset ? srst is active low ? internal configuration: 33k typ. pull up resistor input pll init pll initialization signal ? pll init is active low ? internal configuration: 33k typ. pull up resistor input clkea plc external clock input ? clkea must be connected to one terminal of a crystal (when a crystal is being used) or used as input for external clock signal input clkeb plc external clock input/output ? clkeb must be connected to one terminal of a crystal (when a crystal is being used) or must be floating when an external clock signal is connected thru clkea i/o clkout 10mhz external clock output output vddio plc digital pads 3.3v power supply power vddpll plc plc pll power supply power vddin plc plc digital regulator input power vddout plc plc digital regulator output power vddin an plc analog regulator input power vddout an plc analog regulator output power gnd digital ground power agnd analog ground power
424 sam4cp [datasheet] 43051e?atpl?08/14 27.6 peripheral registers a total of 768 bytes are reserved on-chip to allocate the system peripheral registers. a detailed description of each peripheral register can be found in its corresponding section. on the next pages, there is a list of all of them. table 27-3. register mapping address register name access reset 0xfd00 - 0xfd03 tx time registers txrxbuf_emitime_tx0 read/write 0x00..00 0xfd04 - 0xfd07 txrxbuf_emitime_tx1 read/write 0x00..00 0xfd08 - 0xfd0b txrxbuf_emitime_tx2 read/write 0x00..00 0xfd0c - 0xfd0f txrxbuf_emitime_tx3 read/write 0x00..00 0xfd10 - 0xfd11 tx post-activation time txrx registers txrxbuf_txrx_ta_tx0 read/write 0x0000 0xfd12 - 0xfd13 txrxbuf_txrx_ta_tx1 read/write 0x0000 0xfd14 - 0xfd15 txrxbuf_txrx_ta_tx2 read/write 0x0000 0xfd16 - 0xfd17 txrxbuf_txrx_ta_tx3 read/write 0x0000 0xfd18 - 0xfd19 tx pre-activation time txrx registers txrxbuf_txrx_tb_tx0 read/write 0x0000 0xfd1a - 0xfd1b txrxbuf_txrx_tb_tx1 read/write 0x0000 0xfd1c - 0xfd1d txrxbuf_txrx_tb_tx2 read/write 0x0000 0xfd1e - 0xfd1f txrxbuf_txrx_tb_tx3 read/write 0x0000 0xfd20 global amplitude registers txrxbuf_glbl_amp_tx0 read/write 0xff 0xfd21 txrxbuf_glbl_amp_tx1 read/write 0xff 0xfd22 txrxbuf_glbl_amp_tx2 read/write 0xff 0xfd23 txrxbuf_glbl_amp_tx3 read/write 0xff 0xfd24 signal amplitude registers txrxbuf_sgnl_amp_tx0 read/write 0x60 0xfd25 txrxbuf_sgnl_amp_tx1 read/write 0x60 0xfd26 txrxbuf_sgnl_amp_tx2 read/write 0x60 0xfd27 txrxbuf_sgnl_amp_tx3 read/write 0x60 0xfd28 chirp amplitude registers txrxbuf_chirp_amp_tx0 read/write 0x60 0xfd29 txrxbuf_chirp_amp_tx1 read/write 0x60 0xfd2a txrxbuf_chirp_amp_tx2 read/write 0x60 0xfd2b txrxbuf_chirp_amp_tx3 read/write 0x60 0xfd2c - 0xfd2f tx timeout registers txrxbuf_timeout_tx0 read/write 0x000124f8 0xfd30 - 0xfd33 txrxbuf_timeout_tx1 read/write 0x000124f8 0xfd34 - 0xfd37 txrxbuf_timeout_tx2 read/write 0x000124f8 0xfd38 - 0xfd3b txrxbuf_timeout_tx3 read/write 0x000124f8 0xfd3c tx configuration registers txrxbuf_txconf_tx0 read/write 0xa0 0xfd3d txrxbuf_txconf_tx1 read/write 0xa0 0xfd3e txrxbuf_txconf_tx2 read/write 0xa0 0xfd3f txrxbuf_txconf_tx3 read/write 0xa0 0xfd40 - 0xfd41 tx initial address registers txrxbuf_initad_tx0 read/write 0x0000 0xfd42 - 0xfd43 txrxbuf_initad_tx1 read/write 0x0000 0xfd44 - 0xfd45 txrxbuf_initad_tx2 read/write 0x0000 0xfd46 - 0xfd47 txrxbuf_initad_tx3 read/write 0x0000
425 sam4cp [datasheet] 43051e?atpl?08/14 0xfd48 - 0xfd49 reserved - - 0x0000 0xfd4a - 0xfd4b - - 0x0000 0xfd4c - 0xfd4d - - 0x0000 0xfd4e - 0xfd4f - - 0x0000 0xfd50 - 0xfd51 tx result register txrxbuf_result_tx read-only 0x1111 0xfd52 tx interrupts register txrxbuf_tx_int read-only 0x00 0xfd53 reserved - - 0x00 0xfd54 - - 0x00 0xfd55 - - 0x00 0xfd56 - - 0x00 0xfd57 ber soft average error registers txrxbuf_bersoft_avg_rx0 read-only 0x00 0xfd58 txrxbuf_bersoft_avg_rx1 read-only 0x00 0xfd59 txrxbuf_bersoft_avg_rx2 read-only 0x00 0xfd5a txrxbuf_bersoft_avg_rx3 read-only 0x00 0xfd5b ber soft maximum error registers txrxbuf_bersoft_max_rx0 read-only 0x00 0xfd5c txrxbuf_bersoft_max_rx1 read-only 0x00 0xfd5d txrxbuf_bersoft_max_rx2 read-only 0x00 0xfd5e txrxbuf_bersoft_max_rx3 read-only 0x00 0xfd5f reserved - - 0x00 0xfd60 - - 0x00 0xfd61 - - 0x00 0xfd62 - - 0x00 0xfd63 ber hard average error registers txrxbuf_berhard_avg_rx0 read-only 0x00 0xfd64 txrxbuf_berhard_avg_rx1 read-only 0x00 0xfd65 txrxbuf_berhard_avg_rx2 read-only 0x00 0xfd66 txrxbuf_berhard_avg_rx3 read-only 0x00 0xfd67 ber hard maximum error registers txrxbuf_berhard_max_rx0 read-only 0x00 0xfd68 txrxbuf_berhard_max_rx1 read-only 0x00 0xfd69 txrxbuf_berhard_max_rx2 read-only 0x00 0xfd6a txrxbuf_berhard_max_rx3 read-only 0x00 0xfd6b minimum rssi registers txrxbuf_rssimin_rx0 read-only 0x00 0xfd6c txrxbuf_rssimin_rx1 read-only 0x00 0xfd6d txrxbuf_rssimin_rx2 read-only 0x00 0xfd6e txrxbuf_rssimin_rx3 read-only 0x00 0xfd6f average rssi registers txrxbuf_rssiavg_rx0 read-only 0x00 0xfd70 txrxbuf_rssiavg_rx1 read-only 0x00 0xfd71 txrxbuf_rssiavg_rx2 read-only 0x00 0xfd72 txrxbuf_rssiavg_rx3 read-only 0x00 0xfd73 maximum rssi registers txrxbuf_rssimax_rx0 read-only 0x00 0xfd74 txrxbuf_rssimax_rx1 read-only 0x00 0xfd75 txrxbuf_rssimax_rx2 read-only 0x00 0xfd76 txrxbuf_rssimax_rx3 read-only 0x00 table 27-3. register mapping (continued) address register name access reset
426 sam4cp [datasheet] 43051e?atpl?08/14 0xfd77 minimum cinr registers txrxbuf_cinrmin_rx0 read-only 0x00 0xfd78 txrxbuf_cinrmin_rx1 read-only 0x00 0xfd79 txrxbuf_cinrmin_rx2 read-only 0x00 0xfd7a txrxbuf_cinrmin_rx3 read-only 0x00 0xfd7b average cinr registers txrxbuf_cinravg_rx0 read-only 0x00 0xfd7c txrxbuf_cinravg_rx1 read-only 0x00 0xfd7d txrxbuf_cinravg_rx2 read-only 0x00 0xfd7e txrxbuf_cinravg_rx3 read-only 0x00 0xfd7f maximum cinr registers txrxbuf_cinrmax_rx0 read-only 0x00 0xfd80 txrxbuf_cinrmax_rx1 read-only 0x00 0xfd81 txrxbuf_cinrmax_rx2 read-only 0x00 0xfd82 txrxbuf_cinrmax_rx3 read-only 0x00 0xfd83 - 0xfd86 rx time registers txrxbuf_rectime_rx0 read-only 0x00..00 0xfd87 - 0xfd8a txrxbuf_rectime_rx1 read-only 0x00..00 0xfd8b - 0xfd8e txrxbuf_rectime_rx2 read-only 0x00..00 0xfd8f - 0xfd92 txrxbuf_rectime_rx3 read-only 0x00..00 0xfd93 - 0xfd96 zero-cross time registers txrxbuf_zct_rx0 read-only 0x00..00 0xfd97 - 0xfd9a txrxbuf_zct_rx1 read-only 0x00..00 0xfd9b - 0xfd9e txrxbuf_zct_rx2 read-only 0x00..00 0xfd9f - 0xfda2 txrxbuf_zct_rx3 read-only 0x00..00 0xfda3 - 0xfda4 header evm registers txrxbuf_evm_hd_rx0 read-only 0x0000 0xfda5 - 0xfda6 txrxbuf_evm_hd_rx1 read-only 0x0000 0xfda7 - 0xfda8 txrxbuf_evm_hd_rx2 read-only 0x0000 0xfda9 - 0xfdaa txrxbuf_evm_hd_rx3 read-only 0x0000 0xfdab - 0xfdac payload evm registers txrxbuf_evm_pyld_rx0 read-only 0x0000 0xfdad - 0xfdae txrxbuf_evm_pyld_rx1 read-only 0x0000 0xfdaf - 0xfdb0 txrxbuf_evm_pyld_rx2 read-only 0x0000 0xfdb1 - 0xfdb2 txrxbuf_evm_pyld_rx3 read-only 0x0000 0xfdb3 - 0xfdb6 accumulated header evm registers txrxbuf_evm_hdacum_rx0 read-only 0x00..00 0xfdb7 - 0xfdba txrxbuf_evm_hdacum_rx1 read-only 0x00..00 0xfdbb - 0xfdbe txrxbuf_evm_hdacum_rx2 read-only 0x00..00 0xfdbf - 0xfdc2 txrxbuf_evm_hdacum_rx3 read-only 0x00..00 0xfdc3 - 0xfdc6 accumulated payload evm registers txrxbuf_evm_pylacum_rx0 read-only 0x00..00 0xfdc7 - 0xfdca txrxbuf_evm_pylacum_rx1 read-only 0x00..00 0xfdcb - 0xfdce txrxbuf_evm_pylacum_rx2 read-only 0x00..00 0xfdcf - 0xfdd2 txrxbuf_evm_pylacum_rx3 read-only 0x00..00 0xfdd3 buffer selection register txrxbuf_select_buff_rx read/write 0x00 0xfdd4 rx interrupts register txrxbuf_rx_int read/write 0x00 0xfdd5 rx configuration register txrxbuf_rxconf read/write 0x02 table 27-3. register mapping (continued) address register name access reset
427 sam4cp [datasheet] 43051e?atpl?08/14 0xfdd6 - 0xfdd7 rx initial address registers txrxbuf_initad_rx0 read/write 0x0000 0xfdd8 - 0xfdd9 txrxbuf_initad_rx1 read/write 0x0000 0xfdda - 0xfddb txrxbuf_initad_rx2 read/write 0x0000 0xfddc - 0xfddd txrxbuf_initad_rx3 read/write 0x0000 0xfdde - 0xfde1 reserved - - 0x00..00 0xfde2 - 0xfde5 reserved - - 0x00..00 0xfde6 reserved - - 0x00 0xfde7 - - 0x00 0xfde8 - - 0x00 0xfde9 - - 0x00 0xfdea - 0xfdeb reserved - - 0x0000 0xfdec - 0xfded - - 0x0000 0xfdee - 0xfdef - - 0x0000 0xfdf0 - 0xfdf1 - - 0x0000 0xfdf2 robust tx control register txrxbuf_txconf_robo_ctl read/write 0x00 0xfdf3 robust rx mode register txrxbuf_rxconf_robo_mode read-only 0x00 0xfdf4 - 0xfdf7 reserved - - 0x00..00 0xfdf8 - 0xfdf9 reserved - - 0x0000 0xfdfa reserved - - 0xe0 0xfdfb branch selection register txrxbuf_txconf_selbranch read/write 0x00 0xfdfc reserved - - 0x00 0xfdfd reserved - - 0x00 0xfdfe reserved - - 0x00 0xfdff reserved - - 0x00 0xfe2a phy layer special function register phy_sfr read/write 0x87 0xfe2c system configuration register sys_config read/write 0x04 0xfe30 reserved - - 0x00 0xfe31 - - 0x00 0xfe32 - - 0x00 0xfe33 - - 0x00 0xfe34 - - 0x00 0xfe35 - - 0x00 0xfe36 - - 0x00 0xfe37 - - 0x00 0xfe38 reserved - - 0x40 0xfe39 - - 0x40 0xfe3a - - 0x40 0xfe3b - - 0x40 table 27-3. register mapping (continued) address register name access reset
428 sam4cp [datasheet] 43051e?atpl?08/14 0xfe3c reserved - - 0x10 0xfe3d - - 0x10 0xfe3e - - 0x10 0xfe3f - - 0x10 0xfe47 - 0xfe4a phy layer timer register timer_beacon_ref read-only 0x00..00 0xfe53 - 0xfe55 reserved - - 0x000200 0xfe57 reserved - - 0x1e 0xfe5c reserved - - 0x0c 0xfe5d - - 0x18 0xfe5f - - 0x26 0xfe60 - - 0x2b 0xfe62 - 0xfe67 sub network address register sna read/write 0x00..00 0xfe68 reserved - - 0x5f 0xfe69 - 0xfe6a reserved - - 0xffff 0xfe6b - 0xfe6c - - 0xffff 0xfe6d - 0xfe6e - - 0xffff 0xfe6f - 0xfe70 - - 0xffff 0xfe71 - 0xfe72 - - 0xffff 0xfe73 reserved - - 0x56 0xfe7d - 0xfe7e reserved - - 0x814c 0xfe7f reserved - - 0x00 0xfe80 - 0xfe81 reserved - - 0x0000 0xfe8f reserved - - 0x03 0xfe90 txrx polarity selector register afe_ctl read/write 0x00 0xfe91 reserved - - 0x1e 0xfe92 reserved - - 0x28 0xfe94 phy layer error counter register phy_errors read/write 0x00 0xfe9d reserved - - 0x21 0xfe9e reserved - - 0x05 0xfe9f reserved - - 0x60 0xfea0 reserved - - 0x60 0xfea1 reserved - - 0x60 0xfea2 reserved - - 0x60 0xfea3 - 0xfea6 reserved - - 0x77777777 0xfeab - 0xfeac reserved - - 0x5508 0xfead - 0xfeae reserved - - 0x3c20 0xfeaf reserved - - 0x00 0xfeb0 reserved - - 0x00 0xfeb4 reserved - - 0x00 table 27-3. register mapping (continued) address register name access reset
429 sam4cp [datasheet] 43051e?atpl?08/14 0xfeb5 - 0xfeb6 reserved - - 0x0066 0xfeb7 reserved - - 0x00 0xfeba - 0xfebb crc32 errors counter register err_crc32_mac read-only 0x0000 0xfebc - 0xfebd crc8 errors counter register err_crc8_mac read-only 0x0000 0xfec0 - 0xfec1 crc8 hd errors counter register err_crc8_mac_hd read-only 0x0000 0xfec2 - 0xfec3 crc8 phy errors counter register err_crc8_phy read-only 0x0000 0xfec4 false positive configuration register false_positive_config read/write 0x10 0xfec5 - 0xfec6 false positive counter register false_positive read-only 0x0000 0xfec8 reserved - - 0x3f 0xfec9 reserved - - 0x3f 0xfeca reserved - - 0x3f 0xfecb reserved - - 0x3f 0xfecc reserved - - 0x3f 0xfecd reserved - - 0x3f 0xfece - 0xfecf reserved - - 0x0000 0xfed3 reserved - - 0x40 0xfed5 - 0xfed6 reserved - - 0x0000 0xfedb reserved - - 0x00 0xfedc - 0xfedf reserved - - 0x00..00 0xfee0 reserved - - 0x02 0xfee4 - 0xfee5 reserved - - 0x0000 0xfee6 - 0xfee7 reserved - - 0x0000 0xfee8 reserved - - 0x00 0xfee9 reserved - - 0xff 0xfeea reserved - - 0x04 0xfeeb reserved - - 0x08 0xfeec reserved - - 0x0c 0xfeed reserved - - 0x14 0xfeee reserved - - 0x00 0xfeef reserved - - 0x03 0xfef0 reserved - - 0x00 0xfef1 reserved - - 0x17 0xfef2 reserved - - 0x18 0xfef3 reserved - - 0x23 0xfef4 crc primeplus configuration register primeplus_crc_config read/write 0x14 0xfef5 - 0xfef6 crc primeplus polynomial register primeplus_crc_poly read/write 0x080f table 27-3. register mapping (continued) address register name access reset
430 sam4cp [datasheet] 43051e?atpl?08/14 0xfef7 - 0xfef8 crc primeplus reset value register primeplus_crc_rst read/write 0x0000 0xfefa - 0xfefd channel selector register ctps read/write 0x000150c7 0xfefe reserved - - 0x00 0xff00 - 0xff07 reserved - - 0x411a1803 73d6893c 0xff09 - 0xff0a reserved - - 0x0ea5 0xff0e - 0xff11 peripheral crc polynomial register vcrc_poly read/write 0x04c11db7 0xff12 - 0xff15 peripheral crc reset value register vcrc_rst read/write 0x00..00 0xff16 peripheral crc configuration register vcrc_conf read/write 0xc3 0xff17 peripheral crc input register vcrc_input read/write 0x00 0xff18 peripheral crc control register vcrc_ctl read/write 0x00 0xff19 - 0xff1c peripheral crc value register vcrc_crc read-only 0x00..00 0xff1e reserved - - 0x00 0xff1f - 0xff20 reserved - - 0x051e 0xff21 - 0xff22 reserved - - 0x8000 0xff23 reserved - - 0xb2 0xff24 - 0xff27 reserved - - 0x00030d40 0xff28 - 0xff2b reserved - - 0x00..00 0xff2d reserved - - 0x01 0xff33 - 0xff36 reserved - - 0x00..00 0xff37 - 0xff38 reserved - - 0x0000 0xff39 reserved - - 0x14 0xff3a reserved - - 0x80 0xff3b reserved - - 0x70 0xff3c reserved - - 0xc8 0xff3d reserved - - 0x0a 0xff3e reserved - - 0x02 0xff3f reserved - - 0x04 0xff40 reserved - - 0x01 0xff41 reserved - - 0x01 0xff42 reserved - - 0x27 0xff43 reserved - - 0x0a 0xff4c reserved - - 0xa8 0xff51 reserved - - 0x99 0xff52 reserved - - 0xc0 0xff53 reserved - - 0x00 0xff54 reserved - - 0x03 table 27-3. register mapping (continued) address register name access reset
431 sam4cp [datasheet] 43051e?atpl?08/14 0xff55 reserved - - 0x99 0xff56 reserved - - 0x99 0xff57 reserved - - 0xff 0xff58 reserved - - 0x33 0xff5e - 0xff5f reserved - - 0x0000 0xff61 reserved - - 0x00 0xff62 reserved - - 0x10 0xff63 - 0xff64 reserved - - 0x00bf 0xff65 - 0xff66 reserved - - 0x03e8 0xff67 - 0xff68 reserved - - 0x0400 0xff69 - 0xff6a reserved - - 0x0f20 0xff6b - 0xff6c reserved - - 0x01ee 0xff6d - 0xff6e reserved - - 0x00bf 0xff6f - 0xff70 - - 0x0160 0xff71 - 0xff72 - - 0x02f0 0xff73 - 0xff74 - - 0x0450 0xff75 reserved - - 0x68 0xff76 reserved - - 0x80 0xff77 reserved - - 0x3b 0xff78 - 0xff79 reserved - - 0x0000 0xff7a - 0xff7f reserved - - 0x00..00 0xff80 reserved - - 0x00 0xff81 reserved - - 0x30 0xff82 - 0xff83 reserved - - 0x0600 0xff84 reserved - - 0x58 0xff85 reserved - - 0x99 0xff86 reserved - - 0x79 0xff87 - 0xff88 reserved - - 0x0021 0xff89 reserved - - 0x03 0xff8a reserved - - 0x01 0xff8b reserved - - 0x02 0xff8c reserved - - 0x04 0xff8d reserved - - 0x7f 0xff8e reserved - - 0x00 0xff92 reserved - - 0x14 0xff93 reserved - - 0x11 0xff94 reserved - - 0x80 0xff95 reserved - - 0x00 0xff96 reserved - - 0x00 0xff97 reserved - - 0x70 0xff98 reserved - - 0xc8 0xff99 reserved - - 0x0a table 27-3. register mapping (continued) address register name access reset
432 sam4cp [datasheet] 43051e?atpl?08/14 0xff9a reserved - - 0x02 0xff9b reserved - - 0x04 0xff9c reserved - - 0x01 0xff9d reserved - - 0x01 0xff9e reserved - - 0x27 0xff9f reserved - - 0x0a 0xffa0 - 0xffaf peripheral aes key register aes_key read/write 0x00..00 0xffb0 - 0xffbf peripheral aes data field register aes_data read/write 0x00..00 0xffc0 peripheral aes control register aes_ctl read/write 0x04 0xffe2 - 0xffe3 reserved - - 0x0424 0xffe4 - 0xffe5 - - 0x0424 0xffe6 - 0xffe7 - - 0x0424 0xffe8 - 0xffe9 - - 0x0424 0xffea - 0xffeb - - 0x0424 0xffec - 0xffed - - 0x0424 0xffee - 0xffef - - 0x0424 0xfff0 - 0xfff1 - - 0x0424 0xfff2 - 0xfff3 - - 0x0424 0xfff4 - 0xfff5 - - 0x0424 0xfff6 - 0xfff7 - - 0x0424 0xfff8 - 0xfff9 - - 0x0424 table 27-3. register mapping (continued) address register name access reset
433 sam4cp [datasheet] 43051e?atpl?08/14 27.7 mac coprocessor pplc accelerators can be used to perform prime mac-specific tasks by hardware, decreasing cpu load from the external mcu/mpu. for that purpose, cyclic redundance check (crc) and aes128 encryption blocks are available in pplc. please refer to atmel doc43048 ?atmel prime implementation? for atmel software package detailed description and functionality. 27.7.1 cyclic redundancy check (crc) 27.7.1.1 prime v1.3 crc there are three types of mac pdus (generic, promotion and beacon) for different purposes, and each one has its own specific crc. there is a hardware implementation of every crc type calculated by the mac layer. this crc hardware- calculation is enabled by default. note that the crc included at the physical layer is also a hardware implementation available (enabled by default). figure 27-3. example: generic mac pdu format and generic mac header detail in transmission all crc bytes are real-time calculated and the last bytes of the mac pdu are overwritten with these values, (provided that the field ht in the first byte of the mac header in transmission data is equal to the corresponding mac pdu type). in reception the crc bytes are also real-time calculated and these bytes are checked with the last bytes of the mac pdu. if the crc is not correct, then an error flag is activated, the complet e frame is discarded, and the corresponding error counter is increased. these counters allow the mac layer to take decisions according to error ratio. for the generic mac pdu , there is an 8-bit crc in the generic mac header, which corresponds to prime hdr.hcs. in reception if this crc doesn?t check successfully, the current frame is discarded and no interruption is generated. this works in the same way as crc for the phy layer (crc ctrl, located in the phy header, see prime specification for further information). there is another crc for the generic mac pdu which is the last field of the gpdu. it is 32 bits long and it is used to detect transmission errors. the crc shall cover the concaten ation of the sna with the gpdu except for the crc field itself. in reception, if the crc is not successful then an internal flag is set and the error counter is increased. for the promotion needed pdu there is an 8-bit crc, calculated with the first 13 bytes of the header. in reception, if this crc is not correct, then an internal flag is set and the corresponding error counter is increased. for the beacon pdu there is a 32-bit crc calculated with the same algorithm as the one defined for the crc of the generic mac pdu. this crc shall be calculated over the complete bpdu except for the crc field itself. in reception, if this crc is not successful, then an internal flag is set and the same error counter used for gpdu is increased. the hardware used for this crc is the same as the one used for gpdu. generic mac header packet 1 . . . packet n crc unused hdr.ht reserved reserved hdr.do hdr. level hdr. hcs msb lsb
434 sam4cp [datasheet] 43051e?atpl?08/14 27.7.1.2 configurable crc calculation prime v1.3 version fixes the polynomial to calculate the crcs. in case that these polynomials were modified, the crc peripheral would be used. it is used as a peripheral unit, accessible with several registers mapped in memory. for example, to configure it for prime crc8: x^8 + x^2 + x + 1 vcrc_poly = 0x00000007 vcrc_rst = 0x00000000 vcrc_conf = 0xc0 and to configure it for prime crc32: x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1 vcrc_poly = 0x04c11db7 vcrc_rst = 0x00000000 vcrc_conf = 0xc3 a different set of registers can also be used to set crc parameters: x^12 + x^11 + x^3 + x^2 + x + 1 primeplus_crc_poly = 0x080f primeplus_crc_rst = 0x0000 primeplus_crc_config = 0x14 27.7.2 advanced encryption standard (aes) one of the additional security functionalities to prime v1.3 is the 128-bit aes encryption of data. pplc includes a hardware implementation of this block, as a peripheral unit. in transmission, data must be encrypted previously to the use of the phy_data request primitive (see prime specification), in an independent way (note that beacon pdu, promotion pdu and generic mac header, as well as several control packets, are not encrypted). in reception, data passed by the phy layer is already encrypted and must be decrypted in a subsequent process. to encrypt a data package with corresponding key, the process is as follows: 1. write the key (128 bits long) in aes_key register. this step is only needed if a new key is going to be used (due to a key change or to a reset operation). 2. write the 128 bits of data to be encrypted in aes_data register. 3. set to ?1? the cipher control bit in aes_ctl register and then set to ?1? the start control bit to start the operation. this step could be realized as an atomic operation writing 0x03. 4. wait until the ready bit in aes_ctl register becomes ?1? automatically. this bit indicates when the operation is completed. 5. after that, the encrypted (coded) data package is automatically stored in aes_data register.
435 sam4cp [datasheet] 43051e?atpl?08/14 on the other hand, to decrypt a data package with corresponding key, the process is as follows: 1. write the key (128 bits long) in aes_key register. this step is only needed if a new key is going to be used (due to a key change or to a reset operation). 2. write the 128 bits of encrypted data in aes_data register. 3. set to ?0? the cipher control bit in aes_ctl register and then set to ?1? the start control bit to start the operation. this step could be realized as an atomic operation writing 0x02. 4. wait until the ready bit in aes_ctl register becomes ?1? automatically. this bit indicates when the operation is completed. 5. after that, the decrypted (decoded) data package is automatically stored in aes_data register.
436 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3 mac coprocessor registers 27.7.3.1 crc registers 27.7.3.1.1 sub network address register name: sna address: 0xfe62 ? 0xfe67 access: read/write reset: 0x00..00 this register stores the 48-bit sub network address. physical layer uses it to calculate the crc?s. 47 46 45 44 43 42 41 40 sna (47:40) 39 38 37 36 35 34 33 32 sna (39:32) 31 30 29 28 27 26 25 24 sna (31:24) 23 22 21 20 19 18 17 16 sna (23:16) 15 14 13 12 11 10 9 8 sna (15:8) 76543210 sna (7:0)
437 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.2 crc32 errors counter register name: err_crc32_mac address: 0xfeba (msb) ? 0xfebb (lsb) access: read-only reset: 0x0000 this register stores the number of received prime v1.3 packets (beacon and generic) with an error in the crc32 mac field of the payload, since the last physical layer reset. only a physical layer reset initializes the register. note: once the register has reached its maximum value, a new error causes the register to roll over. 15 14 13 12 11 10 9 8 err_crc32_mac (15:8) 76543210 err_crc32_mac (7:0)
438 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.3 crc8 errors counter register name: err_crc8_mac address: 0xfebc (msb) ? 0xfebd (lsb) access: read-only reset: 0x0000 this register stores the number of received prime v1.3 packets (promotion) with an error in the crc8 mac field of the payload, since the last physical layer reset. only a physical layer reset initializes the register. note: once the register has reached its maximum value, a new error causes the register to roll over. 15 14 13 12 11 10 9 8 err_crc8_mac (15:8) 76543210 err_crc8_mac (7:0)
439 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.4 crc8 hd errors counter register name: err_crc8_mac_hd address: 0xfec0 (msb) ? 0xfec1 (lsb) access: read-only reset: 0x0000 this register stores the number of received prime v1.3 packets with an error in the crc8 mac field of the header, since the last physical layer reset. only a physical layer reset initializes the register. note: once the register has reached its maximum value, a new error causes the register to roll over. 15 14 13 12 11 10 9 8 err_crc8_mac_hd (15:8) 76543210 err_crc8_mac_hd (7:0)
440 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.5 crc8 phy errors counter register name: err_crc8_phy address: 0xfec2 (msb) ? 0xfec3 (lsb) access: read-only reset: 0x0000 this register stores the number of received prime v1.3 packets with an error in the crc8 phy field of the header, since the last physical layer reset. only a physical layer reset initializes the register. note: once the register has reached its maximum value, a new error causes the register to roll over. 15 14 13 12 11 10 9 8 err_crc8_phy (15:8) 76543210 err_crc8_phy (7:0)
441 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.6 crc primeplus configuration register name: primeplus_crc_config address: 0xfef4 access: read/write reset: 0x14 primeplus_crc_config register allows the user to configure feedback type and width of the prime + robust modes physical crc computation algorithm. ? fb_type: ?0?: computation procedure must end with extra bytes with value zero added to the data ones (user added). ?1?: extra bytes addition is not required. ? width (3:0): represents the grade of the polynomial used by the algorithm. 76543210 - - - fb_type width width (3:0) polynomial bits 08 19 210 311 412 513 614 715 >7 16
442 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.7 crc primeplus polynomial register name: primeplus_crc_poly address: 0xfef5 (msb) ? 0xfef6 (lsb) access: read/write reset: 0x080f this register allows the prime + robust modes physical crc polynomial configuration. each bit of the register represents a grade coefficient selected by its position into the register. for example the reset value 0x080f corresponds to the polynomial x^12 + x^11 + x^3 + x^2 + x + 1. in this polynomial the active coefficients are 12,11,3,2,1,0. the most significant coefficient (12) represents the polynomial grade and is implemented by the algorithm feedback so it is not included in the register. with the other coefficients we calculate the register value needed as follows: 2^11 + 2^3 + 2^2 + 2^1 + 2^0 = 2063 = 0x080f. 15 14 13 12 11 10 9 8 primeplus_crc_poly (15:8) 76543210 primeplus_crc_poly (7:0)
443 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.8 crc primeplus reset value register name: primeplus_crc_rst address: 0xfef7 (msb) ? 0xfef8 (lsb) access: read/write reset: 0x0000 this register stores the initial value of the prime + robust modes physical crc computation algorithm. 15 14 13 12 11 10 9 8 primeplus_crc_rst (15:8) 76543210 primeplus_crc_rst (7:0)
444 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.9 peripheral crc polynomial register name: vcrc_poly address: 0xff0e (msb) ? 0xff11 (lsb) access: read/write reset: 0x04c11db7 this is a 32 bits register used to store the crc polynomial mathematical expression. each register bit location represents an exponential degree of the polynomial. meaning that, for a register value of 0x04c11db7; the corresponding polynomial expression is x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1. note that, the first exponential degree (x^32) is taken by the feedback of the circuit itself. to configure the system in crc mode, the bit vcrc_poly(0) must be set to ?1?. otherwise, if vcrc_poly(0) is set to ?0? the system works in lfsr (linear feedback shift register) mode. 31 30 .. .. .. .. 1 0 vcrc_poly (31:0)
445 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.10 peripheral crc reset value register name: vcrc_rst address: 0xff12 (msb) ? 0xff15 (lsb) access: read/write reset: 0x00000000 this is a 32 bits register used to store the initial value to start calculating the crc. this value is fixed by either the crc used or by the protocol implemented. 31 30 .. .. .. .. 1 0 vcrc_rst (31:0)
446 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.11 peripheral crc configuration register name: vcrc_conf address: 0xff16 access: read/write reset: 0xc3 this is an 8 bits register used to configure different crcs and lfsrs. this register contains the following control bits: ? fb_type: configures desired circuit feedback type ?0?: select circuit feedback type as below. ?1?: select circuit feedback type as below. ? msbf: allows to choose byte calculation mode ?0?: select the least significant bit (lsb) first to start calculations. ?1?: select the most significant bit (msb) first to start calculations. ? mirrored8: allows to flip (turn over) the desired crc size (bytes) in the 32-bit vcrc_crc register configured by width1 and width0 bits. ?0?: no flipping is performed and the 32-bit vcrc_crc register will remain unalterable as below. ?1?: flip the desired crc size (bytes) in the 32-bit vcrc_crc register configured by the control bits width1 and width0. for example, if control bits width1 and width0 are both set to ?1? (crc size = 4, see link table), it will flip the four blocks of bytes in the register. in another case when crc size = 3 (width1=?1? and width0=?0?), it will flip the first three blocks of bytes (beginning from less significant byte) in the register ignoring the last byte. 76 5 4 3210 fb_type msbf mirrored32 mirrored8 cin cout width1 width0 4 < < < < < 3 2 1 0 + + + input x^5 x^4 x^3 x^2 x^1 x^0 4 < < < < < 3 2 1 0 + + input x^5 x^4 x^3 x^2 x^1 x^0 +
447 sam4cp [datasheet] 43051e?atpl?08/14 ? mirrored32: allows byte shifting in the 32-bit vcrc_crc register. ?0?: no byte shifting is performed and the entire 32-bit vcrc_crc register will remain unalterable as below. ?1?: the 32-bit vcrc_crc register is reorganized by shifting the four blocks of bytes. meaning that, in a byte the msb will become the lsb. after this command, the vcrc_crc register will look as below. both control bits mirrored32 and mirrored8 can be set to ?1? to obtain the two results simultaneously. ? cin: complement (opposite) the input byte of the vcrc_input register ?0?: disable complement. ?1?: enable complement. ? cout: complement (opposite) the output byte of the vcrc_input register ?0?: disable complement. ?1?: enable complement. ? width(1:0): select crc size in bytes: width(1:0) crc size [bytes] ?00? 1 ?01? 2 ?10? 3 ?11? 4
448 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.12 peripheral crc input register name: vcrc_input address: 0xff17 access: read/write reset: 0x00 this is an 8 bits register used to write the input bytes for crc calculations. each time a byte has been written in this register, the vcrc block detects the byte automatically and initiates the operation adding this new byte to previous calculations. 76543210 vcrc_input (7:0)
449 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.13 peripheral crc control register name: vcrc_ctl address: 0xff18 access: read/write reset: 0x00 the vcrc_ctl register contains the following control bits: ? busy: ? ?0?: vcrc block is ready to receive a new data byte. ? ?1?: vcrc block is busy performing calculations. unable to write in vcrc_input register. ? restart: configures desired circuit feedback type: ? ?0?: reset disable. after a reset, restart bit is set to ?0? automatically after a period of time. ? ?1?: reset enable. delete the actual vcrc_crc register value and does not affect configuration registers. 76543210 0 0 0 busy 0 0 0 restart
450 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.1.14 peripheral crc value register name: vcrc_crc address: 0xff19 (msb) ? 0xff1c (lsb) access: read-only reset: 0x00000000 this is a 32 bits register containing the final computed crc value. the value in this register depends on the crc size (bytes) selected in the control bits width1 and width0. 31 30 .. .. .. .. 1 0 vcrc_crc (31:0)
451 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.2 aes registers 27.7.3.2.1 peripheral aes key register name: aes_key address: 0xffa0 (msb) ? 0xffaf (lsb) access: read/write reset: 0x00..00 the register aes_key is used to store the 128 bits ?key? of the encryption algorithm. 127 126 .. .. .. .. 1 0 aes_key (127:0)
452 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.2.2 peripheral aes data field register name: aes_data address: 0xffb0 (msb) ? 0xffbf (lsb) access: read/write reset: 0x00..00 aes_data register is used to store the encrypted/decrypted data. the size of the data packet for an encryption/decryption operation is always 128 bits. 127 126 .. .. .. .. 1 0 aes_data (127:0)
453 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.2.3 peripheral aes control register name: aes_ctl address: 0xffc0 access: read/write reset: 0x04 the register aes_ctl contains some bits for control operation purposes. ? reset: initializes the aes block: ?0?: reset disabled. ?1?: reset enabled. ? ready: indicates the encryption/decryption ongoing operation: ?0?: indicates encryption/decryption ongoing operation. ?1?: indicates encryption/decryption operation is done. ? start: initialize encrypt/decrypt process: ?1?: start selected functional mode. automatically set to ?0? after process begins. ? cipher: configures functional mode: ?0?: aes block is in decrypt (decode) mode. ?1?: aes block is in encrypt (code) mode. 76543210 - - - reset - ready start cipher
454 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.3 mac info registers 27.7.3.3.1 ber soft average error registers name: txrxbuf_bersoft_avg_rx0 address: 0xfd57 access: read-only reset: 0x00 after a message is received in buf_rx0, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi soft* deci sion. in prime + robust modes, it is calculated from the arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx0. name: txrxbuf_bersoft_avg_rx1 address: 0xfd58 access: read-only reset: 0x00 after a message is received in buf_rx1, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi soft* deci sion. in prime + robust modes, it is calculated from the arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx1. name: txrxbuf_bersoft_avg_rx2 address: 0xfd59 access: read-only reset: 0x00 after a message is received in buf_rx2, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi soft* deci sion. in prime + robust modes, it is calculated from the arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx2. name: txrxbuf_bersoft_avg_rx3 address: 0xfd5a access: read-only reset: 0x00 after a message is received in buf_rx3, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi soft* deci sion. in prime + robust modes, it is calculated from the 76543210 txrxbuf_bersoft_avg_rx0 76543210 txrxbuf_bersoft_avg_rx1 76543210 txrxbuf_bersoft_avg_rx2 76543210 txrxbuf_bersoft_avg_rx3
455 sam4cp [datasheet] 43051e?atpl?08/14 arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx3. * viterbi soft decision: in ?soft? decision there are sixteen decision levels. once decodified, a strong ?0? is represented by a value of ?0?, while a strong ?1? is represented by a value of ?15?. the rest of values are intermediate, so ?7? is used to represent a weak ?0? and ?8? represents a weak ?1?. soft decision calculates the error in one bit received as the distance in decision levels between the value received (a value in the range 0 to 15) and the corrected one (0 or 15). figure 27-4. example of viterbi soft detection decision levels in a bpsk constellation `1 `0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0 s t r o n g e r ` 1 s t r o n g e r ` 0 decision thresholds symbol threshold weak `0 weak `1 1 0 ex example: received value = 0 decodified value = ex error accumulated = +3
456 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.3.2 ber soft maximum error registers name: txrxbuf_bersoft_max_rx0 address: 0xfd5b access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx0, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi soft* decision. the value is cleared by hardware each time a new message is received in buf_rx0. name: txrxbuf_bersoft_max_rx1 address: 0xfd5c access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx1, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi soft* decision. the value is cleared by hardware each time a new message is received in buf_rx1. name: txrxbuf_bersoft_max_rx2 address: 0xfd5d access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx2, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi soft* decision. the value is cleared by hardware each time a new message is received in buf_rx2. name: txrxbuf_bersoft_max_rx3 address: 0xfd5e access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx3, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi soft* decision. the value is cleared by hardware each time a new message is received in buf_rx3. 76543210 txrxbuf_bersoft_max_rx0 76543210 txrxbuf_bersoft_max_rx1 76543210 txrxbuf_bersoft_max_rx2 76543210 txrxbuf_bersoft_max_rx3
457 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.3.3 ber hard average error registers name: txrxbuf_berhard_avg_rx0 address: 0xfd63 access: read-only reset: 0x00 after a message is received in buf_rx0, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi hard* decision. in prime + robust modes, it is calculated from the arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx0. name: txrxbuf_berhard_avg_rx1 address: 0xfd64 access: read-only reset: 0x00 after a message is received in buf_rx1, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi hard* decision. in prime + robust modes, it is calculated from the arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx1. name: txrxbuf_berhard_avg_rx2 address: 0xfd65 access: read-only reset: 0x00 after a message is received in buf_rx2, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi hard* decision. in prime + robust modes, it is calculated from the arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx2. name: txrxbuf_berhard_avg_rx3 address: 0xfd66 access: read-only reset: 0x00 after a message is received in buf_rx3, this register stores the logarithm of the number of accumulated errors regarding the number of received bits, using viterbi hard* decision. in prime + robust modes, it is calculated from the 76543210 txrxbuf_berhard_avg_rx0 76543210 txrxbuf_berhard_avg_rx1 76543210 txrxbuf_berhard_avg_rx2 76543210 txrxbuf_berhard_avg_rx3
458 sam4cp [datasheet] 43051e?atpl?08/14 arithmetic average of the accumulated errors in each one of the four replicated symbols. the value is cleared by hardware each time a new message is received in buf_rx3. * viterbi hard decision: in ?hard? detect ion there are only two decision levels. if the received value is different than the corrected one, the error value taken is ?1?. otherwise, the error value taken is ?0?. figure 27-5. example of viterbi hard detection decision levels in a bpsk constellation `1 `0 s t r o n g e r ` 1 s t r o n g e r ` 0 decision thresholds symbol threshold weak `0 weak `1 1 0 ex example: received value = 0 decodified value = ex error accumulated = +0 = 1 0
459 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.3.4 ber hard maximum error registers name: txrxbuf_berhard_max_rx0 address: 0xfd67 access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx0, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi hard* decision. the value is cleared by hardware each time a new message is received in buf_rx0. name: txrxbuf_berhard_max_rx1 address: 0xfd68 access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx1, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi hard* decision. the value is cleared by hardware each time a new message is received in buf_rx1. name: txrxbuf_berhard_max_rx2 address: 0xfd69 access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx2, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi hard* decision. the value is cleared by hardware each time a new message is received in buf_rx2. name: txrxbuf_berhard_max_rx3 address: 0xfd6a access: read-only reset: 0x00 used only in prime + robust modes. after a message is received in buf_rx3, this register stores the logarithm of the maximum error of the four replicated symbols, regarding the number of received bits, using viterbi hard* decision. the value is cleared by hardware each time a new message is received in buf_rx3. 76543210 txrxbuf_berhard_max_rx0 76543210 txrxbuf_berhard_max_rx1 76543210 txrxbuf_berhard_max_rx2 76543210 txrxbuf_berhard_max_rx3
460 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.3.5 false positive configuration register name: false_positive_config address: 0xfec4 access: read/write reset: 0x10 through false_positive_config register the user is able to configure false_positive register behavior. when a flag of this register is set to ?1?, the correspondent field of the packet is included in the false positive computation algorithm. false positive algorithm is only enabled in prime v1.3 mode. see ?false positive counter register ? ? err_crc8_mac_hd: bad crc8 mac value (the one located at the header part of the packet). ? err_protocol: unsupported protocol field. ? err_len: invalid len field value. len field is located in the prime ppdu header and it defines the length of the payload (after coding) in ofdm symbols. see prime specification for further details about ppdu structure. ? err_pad_len: invalid pad_len value. pad_len field is located in the prime ppdu header and it defines the length of the pad field (after coding) in bytes. see prime specification for further details about ppdu structure. ? err_pdu: unsupported header type. ? err_sp: unsupported security protocol. 76543210 -- err_crc8 _mac_hd err_prot ocol err_len err_pad_ len err_pdu err_sp
461 sam4cp [datasheet] 43051e?atpl?08/14 27.7.3.3.6 false positive counter register name: false_positive address: 0xfec5 (msb) ? 0xfec6 (lsb) access: read-only reset: 0x0000 this register holds the number of received prime v1.3 packets with a good crc8_phy value but with an unsupported value in any of the fields indicated by false_positive_config register. only a physical layer reset initializes the register. note: once the register has reached its maximum value, a new error causes the register to roll over. 15 14 13 12 11 10 9 8 false_positive (15:8) 76543210 false_positive (7:0)
462 sam4cp [datasheet] 43051e?atpl?08/14 27.8 prime phy layer 27.8.1 overview the physical layer consists of a hardware implementation of the enhanced prime physical layer entity, which is an orthogonal frequency division multiplexing (ofdm) system in the 42khz to 472khz frequency band. this phy layer transmits and receives mpdus (mac protocol data unit) between neighbor nodes. from the transmission point of view, the phy layer receives its inputs from the mac (medium access control) layer. at the end of transmission branch, data is output to the physical channel. on the reception side, the phy layer receives its inputs from the physical channel, and at the end of reception branch, the data flows to the mac layer. a phy layer block diagram is shown below: figure 27-6. phy layer block diagram the diagram can be divided in five sub-blocks: txrx buffers, transmission branch, reception branch, analog front end control and carrier detection. crc crc interleaver fft scrambler interleaver ifft prime phy layer tx rx agc(5:0) txrx0 txrx1 convolutional encoder sub-carrier modulator cyclic prefix converter / pad analog front - end control gain control txrx control pre - fft syncro demodulator convolutional decoder to mac layer from mac layer converter buf_txi buf_rxi sub-carrier scrambler carrier detection
463 sam4cp [datasheet] 43051e?atpl?08/14 27.8.1.1 txrx buffers there are 4 dedicated buffers for transmission (buf_tx0, buf_tx1, buf_tx2 and buf_tx3) and 4 dedicated buffers for reception (buf_rx0, buf_rx1, buf_rx2, buf_rx3). the main features are shown below: 27.8.1.2 transmission branch phy layer takes data to be sent from buf_txi. the cyclic redundancy check (crc) fields are hardware-generated in real time, and properly appended to the transmission data. the rest of the chain is hardware-wired, and performs automatically all the tasks needed to send data according to prime specifications. in the following figure , the block diagram of the transmission branch is shown. figure 27-7. transmission branch the output is differential modulated using a dbpsk/dqpsk/d8psk scheme. after modulation, ifft (inverse fourier transform) block and cyclic prefix block allow to implement an ofdm scheme. a converter and a power amplifier driver is the last block in the transmission branch. this block is responsible for adjusting the signal to reach the best transmission efficiency, thus reducing consumption and power dissipation. 27.8.1.3 reception branch the reception branch performs automatically all the tasks needed to process received data. phy layer delivers data to mac layer through the buf_rxi. figure 27-8. reception branch table 27-4. txrx buffers features buf_txi buf_rxi ? size configurable ? number of buffers enabled configurable ? start time forced or programmed ? transmission can be forced regardless of the carrier detection and frames reception ? transmission parameters configurable ? error detector ? size configurable ? number of buffers enabled configurable ? enable/disable interrupts ? parameters saved (ber, rssi, cinr?) crc scrambler interleaver ifft tx convolutional encoder sub - carrier modulator cyclic prefix converter / pad from buf_txi rx to buf_rxi scrambler interleaver convolutional decoder fft sub - carrier demodulator crc pre - fft syncro converter
464 sam4cp [datasheet] 43051e?atpl?08/14 27.8.1.4 analog front end control 27.8.1.4.1 gain control this block implements an automatic gain control (agc) which attenuates the plc input signal via activating some out- puts of the pplc, so there is no saturation and therefore no distortion in the ofdm signal. there are 6 outputs of the pplc controlled by this peripheral. agc0, agc1, agc2, agc3, agc4 and agc5. please see reference design for further information and recommended external circuitry values. 27.8.1.4.2 txrx control this block modifies the configuration of the external analog front end by means of txrx outputs. there are two txrx outputs, one for each txdrv. these digital outputs are used to modify external filter conditions between transmission and reception. to allow different external circuitry topologies, the polarity of both signals can be inverted by hardware (see ?txrx polarity selector register? ). figure 27-9. txrx control block diagram see reference design for further information about txrx control. 27.8.1.5 carrier detection looking for an easy detection of incoming messages, the prime specification defines a carrier detection algorithm that shall be based on preamble detection and header recognition. pplc implements by hardware a set of detection techniques to control access to medium, thus improving frame synchronization in reception and decreasing collision ratio in transmission. 27.8.2 phy parameters a complete description of the prime phy layer can be found in prime specification. please refer to the prime speci- fication provided by the prime alliance in www.prime-alliance.org prime specifies a complete set of primitives to manage the phy layer, and the phy-sap (phy service access point) from mac layer. doc43048 ?atmel prime implementation? integrates all these functions, making them transparent to the final user and simplifying the management. pplc analog front - end control gain control emiter control txdrv0 txdrv1 txrx control txdrv0 agc [0:5] emit [0:5] emit [6:11] txrx0 txrx1 external analog front - end
465 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3 phy layer registers 27.8.3.1 phy configuration registers 27.8.3.1.1 phy layer special function register name: phy_sfr address: 0xfe2a access: read/write reset: 0x87 ? bch_err: busy channel error flag this bit is cleared to ?0? by hardware to indicate the presence of an ofdm signal at the transmission instant. otherwise, this field value is ?1?. this bit is used for returning a result of ?busy channel? in the phy_data confirm primitive (see prime specifi- cation). ? cd: carrier detect bit this bit is set to ?1? by hardware when an ofdm signal is detected, and it is active during the whole reception. this bit is used in channel access (csma-ca algorithm) for performing channel-sensing. ? umd: unsupported modulation scheme flag this flag is set to ?1? by hardware every time a header with correct crc is received, but the protocol field in this header indicates a modulation scheme not supported by the system. ? int_phy: physical layer interruption this bit is internally connected to the eint pin. it is low level active and it is set to '0' by the phy layer to trigger an interrupt in the external host. in reception, every time a plc message is received, the phy layer generates two interrupts. one of them when the physical header is correctly received (two first symbols), and the other one when the message is completely received. in transmission, an interrupt will be generated every time a complete message has been sent. the signal is cleared by writing '1' in the bit phy_sfr(0). 76543210 bch_err cd umd ---- int_phy
466 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.1.2 channel selector register name: ctps address: 0xfefa (msb) ? 0xfefd (lsb) access: read/write reset: 0x000150c7 configures the channel: 31 30 29 28 27 26 25 24 ------- ctps (24) 23 22 21 20 19 18 17 16 ctps (23:16) 15 14 13 12 11 10 9 8 ctps (15:8) 76543210 ctps (7:0) value name description 0x000150c7 channel1 42 - 89 khz 0x00026a44 channel2 97 - 144 khz 0x000383c1 channel3 151 - 198 khz 0x00049d3d channel4 206 - 253 khz 0x0005b6ba channel5 261 - 308 khz 0x0006d036 channel6 315 - 362 khz 0x0007e9b3 channel7 370 - 417 khz 0x00090330 channel8 425 - 472 khz
467 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.2 rx buffers registers 27.8.3.2.1 rx time registers name: txrxbuf_rectime_rx0 address: 0xfd83 ? 0xfd86 access: read-only reset: 0x00000000 reception time in buffer 0. name: txrxbuf_rectime_rx1 address: 0xfd87 ? 0xfd8a access: read-only reset: 0x00000000 reception time in buffer 1. name: txrxbuf_rectime_rx2 address: 0xfd8b ? 0xfd8e access: read-only reset: 0x00000000 reception time in buffer 2. 31 30 29 28 27 26 25 24 txrxbuf_rectime_rx0 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_rectime_rx0 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_rectime_rx0 (15:8) 76543210 txrxbuf_rectime_rx0 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_rectime_rx1 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_rectime_rx1 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_rectime_rx1 (15:8) 76543210 txrxbuf_rectime_rx1 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_rectime_rx2 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_rectime_rx2 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_rectime_rx2 (15:8) 76543210 txrxbuf_rectime_rx2 (7:0)
468 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_rectime_rx3 address: 0xfd8f ? 0xfd92 access: read-only reset: 0x00000000 reception time in buffer 3. when there has been a reception, these registers show when it happened. 31 30 29 28 27 26 25 24 txrxbuf_rectime_rx3 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_rectime_rx3 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_rectime_rx3 (15:8) 76543210 txrxbuf_rectime_rx3 (7:0)
469 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.2.2 buffer selection register name: txrxbuf_select_buff_rx address: 0xfdd3 access: read/write reset: 0x00 select reception buffer: it is used to establish what reception buffers are active. ? sb0: select buffer 0 0: disable buffer 1: enable buffer ? sb1: select buffer 1 0: disable buffer 1: enable buffer ? sb2: select buffer 2 0: disable buffer 1: enable buffer ? sb3: select buffer 3 0: disable buffer 1: enable buffer 76543210 ----sb3sb2sb1sb0
470 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.2.3 rx interrupts register name: txrxbuf_rx_int address: 0xfdd4 access: read/write reset: 0x00 interrupt reception register: when there is some issue with the reception, the micro is warned and then micro tests what buffer is affected through this register. ? pi_rx3: notice payload interrupt reception buffer 3 ? pi_rx2: notice payload interrupt reception buffer 2 ? pi_rx1: notice payload interrupt reception buffer 1 ? pi_rx0: notice payload interrupt reception buffer 0 ? hi_rx3: notice header interrupt reception buffer 3 ? hi_rx2: notice header interrupt reception buffer 2 ? hi_rx1: notice header interrupt reception buffer 1 ? hi_rx0: notice header interrupt reception buffer 0 76543210 pi_rx3 pi_rx2 pi_rx1 pi_rx0 hi_rx3 hi_rx2 hi_rx1 hi_rx0
471 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.2.4 rx configuration register name: txrxbuf_rxconf address: 0xfdd5 access: read/write reset: 0x02 this register permits us configure/know several features in reception: ? disable an active reception interrupt. ? knowing what buffer will be the next to be written. ? enable/disable header interruptions. ? activate/deactivate the overwrite mode in buffer reception when a reception is received. ? dis_rx3: disable interrupt buffer 3 0: enabled 1: disabled ? dis_rx2: disable interrupt buffer 2 0: enabled 1: disabled ? dis_rx1: disable interrupt buffer 1 0: enabled 1: disabled ? dis_rx0: disable interrupt buffer 0 0: enabled 1: disabled ? next_buf: it shows the next buffer which will be written 0: buffer 0 1: buffer 1 2: buffer 2 3: buffer 3 ? eh: disable header interruptions 0: disabled 1: enabled ? ms: enable overwrite mode 0: disabled 1: enabled 76543210 dis_rx3 dis_rx2 dis_rx1 dis_rx0 next_buf eh ms
472 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.2.5 rx initial address registers name: txrxbuf_initad_rx0 address: 0xfdd6 - 0xfdd7 access: read/write reset: 0x0000 initial address of reception buffer 0. name: txrxbuf_initad_rx1 address: 0xfdd8 - 0xfdd9 access: read/write reset: 0x0000 initial address of reception buffer 1. name: txrxbuf_initad_rx2 address: 0xfdda - 0xfddb access: read/write reset: 0x0000 initial address of reception buffer 2. name: txrxbuf_initad_rx3 address: 0xfddc - 0xfddd access: read/write reset: 0x0000 initial address of reception buffer 3. these four registers contain four pointers to the beginning of the respective rx buffer in peripheral memory (buffer 0 to 3). this way, buffers are configurable in both size and position. 15 14 13 12 11 10 9 8 txrxbuf_initad_rx0 (15:8) 76543210 txrxbuf_initad_rx0 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_initad_rx1 (15:8) 76543210 txrxbuf_initad_rx1 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_initad_rx2 (15:8) 76543210 txrxbuf_initad_rx2 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_initad_rx3 (15:8) 76543210 txrxbuf_initad_rx3 (7:0)
473 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.2.6 robust rx mode register name: txrxbuf_rxconf_robo_mode address: 0xfdf3 access: read-only reset: 0x00 this register shows the reception mode of each rx buffer: ? rc_rx0: buffer 0 reception mode. ? rc_rx1: buffer 1 reception mode. ? rc_rx2: buffer 2 reception mode. ? rc_rx3: buffer 3 reception mode. 76543210 rc_rx3 rc_rx2 rc_rx1 rc_rx0 value name description 0 prime 1.3 mode prime v1.3 1 reserved reserved 2 prime + robust prime + robust reception mode 3 prime + robust c. prime + robust reception backwards compatible mode
474 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3 rx info registers 27.8.3.3.1 minimum rssi registers name: txrxbuf_rssimin_rx0 address: 0xfd6b access: read-only reset: 0x00 this register stores the minimum rssi (received signal strength indication) value measured in the last message received in buf_rx0. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssimin_rx1 address: 0xfd6c access: read-only reset: 0x00 this register stores the minimum rssi (received signal strength indication) value measured in the last message received in buf_rx1. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssimin_rx2 address: 0xfd6d access: read-only reset: 0x00 this register stores the minimum rssi (received signal strength indication) value measured in the last message received in buf_rx2. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssimin_rx3 address: 0xfd6e access: read-only reset: 0x00 this register stores the minimum rssi (received signal strength indication) value measured in the last message received in buf_rx3. the measurement is done at symbol level. the value is stored in db. 76543210 txrxbuf_rssimin_rx0 76543210 txrxbuf_rssimin_rx1 76543210 txrxbuf_rssimin_rx2 76543210 txrxbuf_rssimin_rx3
475 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.2 average rssi registers name: txrxbuf_rssiavg_rx0 address: 0xfd6f access: read-only reset: 0x00 this register stores the average rssi (received signal strength indication) value measured in the last message received in buf_rx0. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssiavg_rx1 address: 0xfd70 access: read-only reset: 0x00 this register stores the average rssi (received signal strength indication) value measured in the last message received in buf_rx1. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssiavg_rx2 address: 0xfd71 access: read-only reset: 0x00 this register stores the average rssi (received signal strength indication) value measured in the last message received in buf_rx2. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssiavg_rx3 address: 0xfd72 access: read-only reset: 0x00 this register stores the average rssi (received signal strength indication) value measured in the last message received in buf_rx3. the measurement is done at symbol level. the value is stored in db. 76543210 txrxbuf_rssiavg_rx0 76543210 txrxbuf_rssiavg_rx1 76543210 txrxbuf_rssiavg_rx2 76543210 txrxbuf_rssiavg_rx3
476 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.3 maximum rssi registers name: txrxbuf_rssimax_rx0 address: 0xfd73 access: read-only reset: 0x00 this register stores the maximum rssi (received signal strength indication) value measured in the last message received in buf_rx0. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssimax_rx1 address: 0xfd74 access: read-only reset: 0x00 this register stores the maximum rssi (received signal strength indication) value measured in the last message received in buf_rx1. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssimax_rx2 address: 0xfd75 access: read-only reset: 0x00 this register stores the maximum rssi (received signal strength indication) value measured in the last message received in buf_rx2. the measurement is done at symbol level. the value is stored in db. name: txrxbuf_rssimax_rx3 address: 0xfd76 access: read-only reset: 0x00 this register stores the maximum rssi (received signal strength indication) value measured in the last message received in buf_rx3. the measurement is done at symbol level. the value is stored in db. 76543210 txrxbuf_rssimax_rx0 76543210 txrxbuf_rssimax_rx1 76543210 txrxbuf_rssimax_rx2 76543210 txrxbuf_rssimax_rx3
477 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.4 minimum cinr registers name: txrxbuf_cinrmin_rx0 address: 0xfd77 access: read-only reset: 0x00 this register stores the minimum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx0. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinrmin_rx1 address: 0xfd78 access: read-only reset: 0x00 this register stores the minimum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx1. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinrmin_rx2 address: 0xfd79 access: read-only reset: 0x00 this register stores the minimum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx2. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinrmin_rx3 address: 0xfd7a access: read-only reset: 0x00 this register stores the minimum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx3. the measurement is done at symbol level. the value is stored in ? db steps. 76543210 txrxbuf_cinrmin_rx0 76543210 txrxbuf_cinrmin_rx1 76543210 txrxbuf_cinrmin_rx2 76543210 txrxbuf_cinrmin_rx3
478 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.5 average cinr registers name: txrxbuf_cinravg_rx0 address: 0xfd7b access: read-only reset: 0x00 this register stores the average cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx0. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinravg_rx1 address: 0xfd7c access: read-only reset: 0x00 this register stores the average cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx1. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinravg_rx2 address: 0xfd7d access: read-only reset: 0x00 this register stores the average cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx2. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinravg_rx3 address: 0xfd7e access: read-only reset: 0x00 this register stores the average cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx3. the measurement is done at symbol level. the value is stored in ? db steps. 76543210 txrxbuf_cinravg_rx0 76543210 txrxbuf_cinravg_rx1 76543210 txrxbuf_cinravg_rx2 76543210 txrxbuf_cinravg_rx3
479 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.6 maximum cinr registers name: txrxbuf_cinrmax_rx0 address: 0xfd7f access: read-only reset: 0x00 this register stores the maximum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx0. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinrmax_rx1 address: 0xfd80 access: read-only reset: 0x00 this register stores the maximum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx1. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinrmax_rx2 address: 0xfd81 access: read-only reset: 0x00 this register stores the maximum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx2. the measurement is done at symbol level. the value is stored in ? db steps. name: txrxbuf_cinrmax_rx3 address: 0xfd82 access: read-only reset: 0x00 this register stores the maximum cinr (carrier to interference + noise ratio) value measured in the last message received in buf_rx3. the measurement is done at symbol level. the value is stored in ? db steps. 76543210 txrxbuf_cinrmax_rx0 76543210 txrxbuf_cinrmax_rx1 76543210 txrxbuf_cinrmax_rx2 76543210 txrxbuf_cinrmax_rx3
480 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.7 header evm registers name: txrxbuf_evm_hd_rx0 address: 0xfda3 - 0xfda4 access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message header in buf_rx0. the 7 msb, txrxbuf_evm_hd_rx0 (15:9), represent the integer part in %, being the txrxbuf_evm_hd_rx0 (8:0) bits the fractional part if more precision were required. this register is used by the physical layer for being in accordance with prime specification. name: txrxbuf_evm_hd_rx1 address: 0xfda5 - 0xfda6 access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message header in buf_rx1. the 7 msb, txrxbuf_evm_hd_rx1 (15:9), represent the integer part in %, being the txrxbuf_evm_hd_rx1 (8:0) bits the fractional part if more precision were required. this register is used by the physical layer for being in accordance with prime specification. name: txrxbuf_evm_hd_rx2 address: 0xfda7 - 0xfda8 access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message header in buf_rx2. the 7 msb, txrxbuf_evm_hd_rx2 (15:9), represent the integer part in %, being the txrxbuf_evm_hd_rx2 (8:0) bits the fractional part if more precision were required. this register is used by the physical layer for being in accordance with prime specification. 15 14 13 12 11 10 9 8 txrxbuf_evm_hd_rx0 (15:8) 76543210 txrxbuf_evm_hd_rx0 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_evm_hd_rx1 (15:8) 76543210 txrxbuf_evm_hd_rx1 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_evm_hd_rx2 (15:8) 76543210 txrxbuf_evm_hd_rx2 (7:0)
481 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_evm_hd_rx3 address: 0xfda9 - 0xfdaa access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message header in buf_rx3. the 7 msb, txrxbuf_evm_hd_rx3 (15:9), represent the integer part in %, being the txrxbuf_evm_hd_rx3 (8:0) bits the fractional part if more precision were required. this register is used by the physical layer for being in accordance with prime specification. 15 14 13 12 11 10 9 8 txrxbuf_evm_hd_rx3 (15:8) 76543210 txrxbuf_evm_hd_rx3 (7:0)
482 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.8 payload evm registers name: txrxbuf_evm_pyld_rx0 address: 0xfdab - 0xfdac access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message payload in buf_rx0. the 7 msb, txrxbuf_evm_pyld_rx0 (15:9), represent the integer part in %, being the txrxbuf_evm_pyld_rx0 (8:0) bits the fractional part if more precision were required. name: txrxbuf_evm_pyld_rx1 address: 0xfdad - 0xfdae access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message payload in buf_rx1. the 7 msb, txrxbuf_evm_pyld_rx1 (15:9), represent the integer part in %, being the txrxbuf_evm_pyld_rx1 (8:0) bits the fractional part if more precision were required. name: txrxbuf_evm_pyld_rx2 address: 0xfdaf - 0xfdb0 access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message payload in buf_rx2. the 7 msb, txrxbuf_evm_pyld_rx2 (15:9), represent the integer part in %, being the txrxbuf_evm_pyld_rx2 (8:0) bits the fractional part if more precision were required. 15 14 13 12 11 10 9 8 txrxbuf_evm_pyld_rx0 (15:8) 76543210 txrxbuf_evm_pyld_rx0 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_evm_pyld_rx1 (15:8) 76543210 txrxbuf_evm_pyld_rx1 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_evm_pyld_rx2 (15:8) 76543210 txrxbuf_evm_pyld_rx2 (7:0)
483 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_evm_pyld_rx3 address: 0xfdb1 - 0xfdb2 access: read-only reset: 0x0000 this register stores the maximum evm (error vector magnitude) measured in the reception of the last message payload in buf_rx3. the 7 msb, txrxbuf_evm_pyld_rx3 (15:9), represent the integer part in %, being the txrxbuf_evm_pyld_rx3 (8:0) bits the fractional part if more precision were required. 15 14 13 12 11 10 9 8 txrxbuf_evm_pyld_rx3 (15:8) 76543210 txrxbuf_evm_pyld_rx3 (7:0)
484 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.9 accumulated header evm registers name: txrxbuf_evm_hdacum_rx0 address: 0xfdb3 - 0xfdb6 access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message header in buf_rx0. name: txrxbuf_evm_hdacum_rx1 address: 0xfdb7 - 0xfdba access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message header in buf_rx1. 31 30 29 28 27 26 25 24 txrxbuf_evm_hdacum_rx0 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_hdacum_rx0 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_hdacum_rx0 (4:0) 0 0 0 76543210 00000000 31 30 29 28 27 26 25 24 txrxbuf_evm_hdacum_rx1 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_hdacum_rx1 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_hdacum_rx1 (4:0) 0 0 0 76543210 00000000
485 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_evm_hdacum_rx2 address: 0xfdbb - 0xfdbe access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message header in buf_rx2. name: txrxbuf_evm_hdacum_rx3 address: 0xfdbf - 0xfdc2 access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message header in buf_rx3. 31 30 29 28 27 26 25 24 txrxbuf_evm_hdacum_rx2 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_hdacum_rx2 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_hdacum_rx2 (4:0) 0 0 0 76543210 00000000 31 30 29 28 27 26 25 24 txrxbuf_evm_hdacum_rx3 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_hdacum_rx3 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_hdacum_rx3 (4:0) 0 0 0 76543210 00000000
486 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.3.10 accumulated payload evm registers name: txrxbuf_evm_pylacum_rx0 address: 0xfdc3 - 0xfdc6 access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message payload in buf_rx0. name: txrxbuf_evm_pylacum_rx1 address: 0xfdc7 - 0xfdca access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message payload in buf_rx1. 31 30 29 28 27 26 25 24 txrxbuf_evm_pylacum_rx0 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_pylacum_rx0 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_pylacum_rx0 (4:0) 0 0 0 76543210 00000000 31 30 29 28 27 26 25 24 txrxbuf_evm_pylacum_rx1 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_pylacum_rx1 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_pylacum_rx1 (4:0) 0 0 0 76543210 00000000
487 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_evm_pylacum_rx2 address: 0xfdcb - 0xfdce access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message payload in buf_rx2. name: txrxbuf_evm_pylacum_rx3 address: 0xfdcf - 0xfdd2 access: read-only reset: 0x00000000 when receiving an ofdm symbol, the total sum of all its individual carriers evms (error vector magnitude) is calculated in order to further calculate the average evm value. this register stores the maximum total sum between the two ofdm symbols received in the last message payload in buf_rx3. 31 30 29 28 27 26 25 24 txrxbuf_evm_pylacum_rx2 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_pylacum_rx2 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_pylacum_rx2 (4:0) 0 0 0 76543210 00000000 31 30 29 28 27 26 25 24 txrxbuf_evm_pylacum_rx3 (20:13) 23 22 21 20 19 18 17 16 txrxbuf_evm_pylacum_rx3 (12:5) 15 14 13 12 11 10 9 8 txrxbuf_evm_pylacum_rx3 (4:0) 0 0 0 76543210 00000000
488 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.4 tx config registers 27.8.3.4.1 global amplitude registers name: txrxbuf_glbl_amp_tx0 address: 0xfd20 access: read/write reset: 0xff being ?amax? the maximum voltage reachable in the external driver mos couple, this register sets the global amplitude for the transmitted frame (chirp+header+payload), when buf_tx0 is used, following this formula: name: txrxbuf_glbl_amp_tx1 address: 0xfd21 access: read/write reset: 0xff being ?amax? the maximum voltage reachable in the external driver mos couple, this register sets the global amplitude for the transmitted frame (chirp+header+payload), when buf_tx1 is used, following this formula: name: txrxbuf_glbl_amp_tx2 address: 0xfd22 access: read/write reset: 0xff being ?amax? the maximum voltage reachable in the external driver mos couple, this register sets the global amplitude for the transmitted frame (chirp+header+payload), when buf_tx2 is used, following this formula: 76543210 txrxbuf_glbl_amp_tx0 76543210 txrxbuf_glbl_amp_tx1 76543210 txrxbuf_glbl_amp_tx2
489 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_glbl_amp_tx3 address: 0xfd23 access: read/write reset: 0xff being ?amax? the maximum voltage reachable in the external driver mos couple, this register sets the global amplitude for the transmitted frame (chirp+header+payload), when buf_tx3 is used, following this formula: 76543210 txrxbuf_glbl_amp_tx3
490 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.4.2 signal amplitude registers name: txrxbuf_sgnl_amp_tx0 address: 0xfd24 access: read/write reset: 0x60 this register stores the amplitude value for the transmitted frame (only header+payload; chirp not affected), when buf_tx0 is used. if this value is equal to 0xff, the header+payload transmitted are not attenuated. if this register is equal to 0x00, the header+payload are nullified. name: txrxbuf_sgnl_amp_tx1 address: 0xfd25 access: read/write reset: 0x60 this register stores the amplitude value for the transmitted frame (only header+payload; chirp not affected), when buf_tx1 is used. if this value is equal to 0xff, the header+payload transmitted are not attenuated. if this register is equal to 0x00, the header+payload are nullified. name: txrxbuf_sgnl_amp_tx2 address: 0xfd26 access: read/write reset: 0x60 this register stores the amplitude value for the transmitted frame (only header+payload; chirp not affected), when buf_tx2 is used. if this value is equal to 0xff, the header+payload transmitted are not attenuated. if this register is equal to 0x00, the header+payload are nullified. name: txrxbuf_sgnl_amp_tx3 address: 0xfd27 access: read/write reset: 0x60 this register stores the amplitude value for the transmitted frame (only header+payload; chirp not affected), when buf_tx3 is used. if this value is equal to 0xff, the header+payload transmitted are not attenuated. if this register is equal to 0x00, the header+payload are nullified. 76543210 txrxbuf_sgnl_amp_tx0 76543210 txrxbuf_sgnl_amp_tx1 76543210 txrxbuf_sgnl_amp_tx2 76543210 txrxbuf_sgnl_amp_tx3
491 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.4.3 chirp amplitude registers name: txrxbuf_chirp_amp_tx0 address: 0xfd28 access: read/write reset: 0x60 this register stores the amplitude value for the transmitted chirp (header and payload not affected), when buf_tx0 is used. if this value is equal to 0xff, the chirp transmitted is not attenuated. if this register is equal to 0x00, the chirp is nullified. name: txrxbuf_chirp_amp_tx1 address: 0xfd29 access: read/write reset: 0x60 this register stores the amplitude value for the transmitted chirp (header and payload not affected), when buf_tx1 is used. if this value is equal to 0xff, the chirp transmitted is not attenuated. if this register is equal to 0x00, the chirp is nullified. name: txrxbuf_chirp_amp_tx2 address: 0xfd2a access: read/write reset: 0x60 this register stores the amplitude value for the transmitted chirp (header and payload not affected), when buf_tx2 is used. if this value is equal to 0xff, the chirp transmitted is not attenuated. if this register is equal to 0x00, the chirp is nullified. name: txrxbuf_chirp_amp_tx3 address: 0xfd2b access: read/write reset: 0x60 this register stores the amplitude value for the transmitted chirp (header and payload not affected), when buf_tx3 is used. if this value is equal to 0xff, the chirp transmitted is not attenuated. if this register is equal to 0x00, the chirp is nullified. 76543210 txrxbuf_chirp_amp_tx0 76543210 txrxbuf_chirp_amp_tx1 76543210 txrxbuf_chirp_amp_tx2 76543210 txrxbuf_chirp_amp_tx3
492 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5 tx buffers registers 27.8.3.5.1 tx time registers name: txrxbuf_emitime_tx0 address: 0xfd00 - 0xfd03 access: read/write reset: 0x00000000 transmission time of buffer 0. name: txrxbuf_emitime_tx1 address: 0xfd04 - 0xfd07 access: read/write reset: 0x00000000 transmission time of buffer 1. name: txrxbuf_emitime_tx2 address: 0xfd08 - 0xfd0b access: read/write reset: 0x00000000 transmission time of buffer 2. 31 30 29 28 27 26 25 24 txrxbuf_emitime_tx0 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_emitime_tx0 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_emitime_tx0 (15:8) 76543210 txrxbuf_emitime_tx0 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_emitime_tx1 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_emitime_tx1 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_emitime_tx1 (15:8) 76543210 txrxbuf_emitime_tx1 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_emitime_tx2 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_emitime_tx2 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_emitime_tx2 (15:8) 76543210 txrxbuf_emitime_tx2 (7:0)
493 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_emitime_tx3 address: 0xfd0c - 0xfd0f access: read/write reset: 0x00000000 transmission time of buffer 3. these registers contain the time value (referenced to the 20-bit phy layer global timer) when a programmed transmission in the corresponding buffer shall begin. 31 30 29 28 27 26 25 24 txrxbuf_emitime_tx3 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_emitime_tx3 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_emitime_tx3 (15:8) 76543210 txrxbuf_emitime_tx3 (7:0)
494 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.2 tx post-activation time txrx registers name: txrxbuf_txrx_ta_tx0 address: 0xfd10 - 0xfd11 access: read/write reset: 0x0000 post-activation time txrx of buffer 0. name: txrxbuf_txrx_ta_tx1 address: 0xfd12 - 0xfd13 access: read/write reset: 0x0000 post-activation time txrx of buffer 1. name: txrxbuf_txrx_ta_tx2 address: 0xfd14 - 0xfd15 access: read/write reset: 0x0000 post-activation time txrx of buffer 2. name: txrxbuf_txrx_ta_tx3 address: 0xfd16 - 0xfd17 access: read/write reset: 0x0000 post-activation time txrx of buffer 3. the user can modify these registers to set the period of time to maintain active (according to polarity) txrx output signals once a transmission has finished. this parameter is useful to improve the external coupling transient response. when automatic txrx has been selected, in these registers must be set this time for the suitable buffer. 15 14 13 12 11 10 9 8 txrxbuf_txrx_ta_tx0 (15:8) 76543210 txrxbuf_txrx_ta_tx0 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_txrx_ta_tx1 (15:8) 76543210 txrxbuf_txrx_ta_tx1 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_txrx_ta_tx2 (15:8) 76543210 txrxbuf_txrx_ta_tx2 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_txrx_ta_tx3 (15:8) 76543210 txrxbuf_txrx_ta_tx3 (7:0)
495 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.3 tx pre-activation time txrx registers name: txrxbuf_txrx_tb_tx0 address: 0xfd18 - 0xfd19 access: read/write reset: 0x0000 pre-activation time txrx of buffer 0. name: txrxbuf_txrx_tb_tx1 address: 0xfd1a - 0xfd1b access: read/write reset: 0x0000 pre-activation time txrx of buffer 1. name: txrxbuf_txrx_tb_tx2 address: 0xfd1c - 0xfd1d access: read/write reset: 0x0000 pre-activation time txrx of buffer 2. name: txrxbuf_txrx_tb_tx3 address: 0xfd1e - 0xfd1f access: read/write reset: 0x0000 pre-activation time txrx of buffer 3. the user can modify these registers to specify the period of time to set active (according to polarity) txrx output signals before a transmission starts. this parameter is useful to improve the external coupling transient response. when automatic txrx has been selected, in these registers must be set this time for the suitable buffer. 15 14 13 12 11 10 9 8 txrxbuf_txrx_tb_tx0 (15:8) 76543210 txrxbuf_txrx_tb_tx0 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_txrx_tb_tx1 (15:8) 76543210 txrxbuf_txrx_tb_tx1 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_txrx_tb_tx2 (15:8) 76543210 txrxbuf_txrx_tb_tx2 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_txrx_tb_tx3 (15:8) 76543210 txrxbuf_txrx_tb_tx3 (7:0)
496 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.4 tx timeout registers name: txrxbuf_timeout_tx0 address: 0xfd2c - 0xfd2f access: read/write reset: 0x000124f8 timeout buffer 0. name: txrxbuf_timeout_tx1 address: 0xfd30 - 0xfd33 access: read/write reset: 0x000124f8 timeout buffer 1. name: txrxbuf_timeout_tx2 address: 0xfd34 - 0xfd37 access: read/write reset: 0x000124f8 timeout buffer 2. 31 30 29 28 27 26 25 24 txrxbuf_timeout_tx0 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_timeout_tx0 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_timeout_tx0 (15:8) 76543210 txrxbuf_timeout_tx0 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_timeout_tx1 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_timeout_tx1 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_timeout_tx1 (15:8) 76543210 txrxbuf_timeout_tx1 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_timeout_tx2 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_timeout_tx2 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_timeout_tx2 (15:8) 76543210 txrxbuf_timeout_tx2 (7:0)
497 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_timeout_tx3 address: 0xfd38 - 0xfd3b access: read/write reset: 0x000124f8 timeout buffer 3. transmission timeout. maximum period of time that the phy layer shall wait before discarding a frame that is waiting to be transmitted. 31 30 29 28 27 26 25 24 txrxbuf_timeout_tx3 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_timeout_tx3 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_timeout_tx3 (15:8) 76543210 txrxbuf_timeout_tx3 (7:0)
498 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.5 tx configuration registers name: txrxbuf_txconf_tx0 address: 0xfd3c access: read/write reset: 0xa0 ? trs0: txrx established by software in buffer 0. txrx established by software for activated/deactivated txrx signal before/after each transmission to work properly transistors when this feature has been selected. 0: disabled 1: enabled ? atr0: txrx control mode in buffer 0. establishing software/hardware control of txrx signal for transmitting. 1 : by hardware 0: by software ? fe0: transmission forced/unforced in buffer 0. when force transmission is required, if it is possible (carrier detection or reception are in course and not disables) and suitable buffer is enabled, a transmission is immediately started. 0: transmission unforced 1: transmission forced ? eb0: buffer 0 enabled/disabled in buffer 0. enable buffer that it has been required. 0: disabled 1: enabled ? dc0: carrier detect enabled/disabled for transmission in buffer 0. starting transmission though carrier detection is in course. 0: enabled 1: disabled ? dr0: reception enabled/disabled for transmission in buffer 0. starting transmission though reception is in course. 0: enabled 1: disabled 76543210 - trs0 atr0 - fe0 eb0 dc0 dr0
499 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_txconf_tx1 address: 0xfd3d access: read/write reset: 0xa0 ? trs1: txrx established by software in buffer 1. txrx established by software for activated/deactivated txrx signal before/after each transmission to work properly transistors when this feature has been selected. 0: disabled 1: enabled ? atr1: txrx control mode in buffer 1. establishing software/hardware control of txrx signal for transmitting. 1 : by hardware 0: by software ? fe1: transmission forced/unforced in buffer 1. when force transmission is required, if it is possible (carrier detection or reception are in course and not disables) and suitable buffer is enabled, a transmission is immediately started. 0: transmission unforced 1: transmission forced ? eb1: buffer 0 enabled/disabled in buffer 1. enable buffer that it has been required. 0: disabled 1: enabled ? dc1: carrier detect enabled/disabled for transmission in buffer 1. starting transmission though carrier detection is in course. 0: enabled 1: disabled ? dr1: reception enabled/disabled for transmission in buffer 1. starting transmission though reception is in course. 0: enabled 1: disabled 76543210 - trs1 atr1 - fe1 eb1 dc1 dr1
500 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_txconf_tx2 address: 0xfd3e access: read/write reset: 0xa0 ? trs2: txrx established by software in buffer 2. txrx established by software for activated/deactivated txrx signal before/after each transmission to work properly transistors when this feature has been selected. 0: disabled 1: enabled ? atr2: txrx control mode in buffer 2. establishing software/hardware control of txrx signal for transmitting. 1 : by hardware 0: by software ? fe2: transmission forced/unforced in buffer 2. when force transmission is required, if it is possible (carrier detection or reception are in course and not disables) and suitable buffer is enabled, a transmission is immediately started. 0: transmission unforced 1: transmission forced ? eb2: buffer 0 enabled/disabled in buffer 2. enable buffer that it has been required. 0: disabled 1: enabled ? dc2: carrier detect enabled/disabled for transmission in buffer 2. starting transmission though carrier detection is in course. 0: enabled 1: disabled ? dr2: reception enabled/disabled for transmission in buffer 2. starting transmission though reception is in course. 0: enabled 1: disabled 76543210 - trs2 atr2 - fe2 eb2 dc2 dr2
501 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_txconf_tx3 address: 0xfd3f access: read/write reset: 0xa0 ? trs3: txrx established by software in buffer 3. txrx established by software for activated/deactivated txrx signal before/after each transmission to work properly transistors when this feature has been selected. 0: disabled 1: enabled ? atr3: txrx control mode in buffer 3. establishing software/hardware control of txrx signal for transmitting. 1 : by hardware 0: by software ? fe3: transmission forced/unforced in buffer 3. when force transmission is required, if it is possible (carrier detection or reception are in course and not disables) and suitable buffer is enabled, a transmission is immediately started. 0: transmission unforced 1: transmission forced ? eb3: buffer 0 enabled/disabled in buffer 3. enable buffer that it has been required. 0: disabled 1: enabled ? dc3: carrier detect enabled/disabled for transmission in buffer 3. starting transmission though carrier detection is in course. 0: enabled 1: disabled ? dr3: reception enabled/disabled for transmission in buffer 3. starting transmission though reception is in course. 0: enabled 1: disabled 76543210 - trs3 atr3 - fe3 eb3 dc3 dr3
502 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.6 tx initial address registers name: txrxbuf_initad_tx0 address: 0xfd40 - 0xfd41 access: read/write reset: 0x0000 initial address of transmission buffer 0. name: txrxbuf_initad_tx1 address: 0xfd42 - 0xfd43 access: read/write reset: 0x0000 initial address of transmission buffer 1. name: txrxbuf_initad_tx2 address: 0xfd44 - 0xfd45 access: read/write reset: 0x0000 initial address of transmission buffer 2. name: txrxbuf_initad_tx3 address: 0xfd46 - 0xfd47 access: read/write reset: 0x0000 initial address of transmission buffer 3. these four registers contain four pointers to the beginning of the respective tx buffer in peripheral memory (buffer 0 to 3). this way, buffers are configurable in both size and position. 15 14 13 12 11 10 9 8 txrxbuf_initad_tx0 (15:8) 76543210 txrxbuf_initad_tx0 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_initad_tx1 (15:8) 76543210 txrxbuf_initad_tx1 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_initad_tx2 (15:8) 76543210 txrxbuf_initad_tx2 (7:0) 15 14 13 12 11 10 9 8 txrxbuf_initad_tx3 (15:8) 76543210 txrxbuf_initad_tx3 (7:0)
503 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.7 tx result register name: txrxbuf_result_tx address: 0xfd50 - 0xfd51 access: read-only reset: 0x1111 this register stores the transmission status of each buffer. 15 14 13 12 11 10 9 8 - et_tx1 - et_tx0 76543210 - et_tx3 - et_tx2 value name description 0 et0_tx transmission in process 1 et1_tx successful transmission 2 et2_tx wrong length 3 et3_tx busy channel 4 et4_tx previous transmission in process 5 et5_tx reception transmission in process 6 et6_tx invalid scheme 7 et7_tx timeout
504 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.8 tx interrupts register name: txrxbuf_tx_int address: 0xfd52 access: read-only reset: 0x00 interrupt register of transmission and noise buffers: ? hi_n: notice interrupt noise buffer ? hi_tx3: notice interrupt transmission buffer 3 ? hi_tx2: notice interrupt transmission buffer 2 ? hi_tx1: notice interrupt transmission buffer 1 ? hi_tx0: notice interrupt transmission buffer 0 when there is some issue with the transmission or noise reception, the micro is warned and then micro tests what buffer is affected through this register. 76543210 --- hi_n hi_tx3 hi_tx2 hi_tx1 hi_tx0
505 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.5.9 robust tx control register name: txrxbuf_txconf_robo_ctl address: 0xfdf2 access: read/write reset: 0x00 this register sets the transmission mode of each tx buffer: ? rc0: buffer 0 transmission mode ? rc1: buffer 1 transmission mode ? rc2: buffer 2 transmission mode ? rc3: buffer 3 transmission mode 76543210 rc3 rc2 rc1 rc0 value name description 0 prime 1.3 mode prime v1.3 1 reserved reserved 2 prime + robust prime + robust transmission mode 3 prime + robust c. prime + robust transmission backwards compatible mode
506 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.6 afe configuration registers 27.8.3.6.1 branch selection register name: txrxbuf_txconf_selbranch address: 0xfdfb access: read/write reset: 0x00 ? br1_tx0: enable/disable emit(0:5) output pins, when buf_tx0 is used 1: enabled 0: disabled ? br2_tx0: enable/disable emit(6:11) output pins, when buf_tx0 is used 1: enabled 0: disabled ? br1_tx1: enable/disable emit(0:5) output pins, when buf_tx1 is used 1: enabled 0: disabled ? br2_tx1: enable/disable emit(6:11) output pins, when buf_tx1 is used 1: enabled 0: disabled ? br1_tx2: enable/disable emit(0:5) output pins, when buf_tx2 is used 1: enabled 0: disabled ? br2_tx2: enable/disable emit(6:11) output pins, when buf_tx2 is used 1: enabled 0: disabled ? br1_tx3: enable/disable emit(0:5) output pins, when buf_tx3 is used 1: enabled 0: disabled ? br2_tx3: enable/disable emit(6:11) output pins, when buf_tx3 is used 1: enabled 0: disabled 76543210 br2_tx3 br1_tx3 br2_tx2 br1_tx2 br2_tx1 br1_tx1 br2_tx0 br1_tx0
507 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.6.2 txrx polarity selector register name: afe_ctl address: 0xfe90 access: read/write reset: 0x00 ? txrx1_pol: txrx1 pin polarity control 0: txrx1 pin output = ?0? in transmission and ?1? in reception. 1: txrx1 pin output = ?1? in transmission and ?0? in reception. ? txrx0_pol: txrx0 pin polarity control 0: txrx0 pin output = ?0? in transmission and ?1? in reception. 1: txrx0 pin output = ?1? in transmission and ?0? in reception. 765432 1 0 ------ txrx1_pol txrx0_pol
508 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.7 zero-crossing registers 27.8.3.7.1 zero-cross time registers name: txrxbuf_zct_rx0 address: 0xfd93 - 0xfd96 access: read-only reset: 0x00000000 instant in time at which the last zero-cross event took place, at the end of the last message received in buf_rx0. it is expressed in 10 s steps. it is set by hardware and is a read-only register. this register is used by the physical layer for being in accordance with prime specification. name: txrxbuf_zct_rx1 address: 0xfd97 - 0xfd9a access: read-only reset: 0x00000000 instant in time at which the last zero-cross event took place, at the end of the last message received in buf_rx1. it is expressed in 10 s steps. it is set by hardware and is a read-only register. this register is used by the physical layer for being in accordance with prime specification. 31 30 29 28 27 26 25 24 txrxbuf_zct_rx0 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_zct_rx0 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_zct_rx0 (15:8) 76543210 txrxbuf_zct_rx0 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_zct_rx1 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_zct_rx1 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_zct_rx1 (15:8) 76543210 txrxbuf_zct_rx1 (7:0)
509 sam4cp [datasheet] 43051e?atpl?08/14 name: txrxbuf_zct_rx2 address: 0xfd9b - 0xfd9e access: read-only reset: 0x00000000 instant in time at which the last zero-cross event took place, at the end of the last message received in buf_rx2. it is expressed in 10 s steps. it is set by hardware and is a read-only register. this register is used by the physical layer for being in accordance with prime specification. name: txrxbuf_zct_rx3 address: 0xfd9f - 0xfda2 access: read-only reset: 0x00000000 instant in time at which the last zero-cross event took place, at the end of the last message received in buf_rx3. it is expressed in 10 s steps. it is set by hardware and is a read-only register. this register is used by the physical layer for being in accordance with prime specification. 31 30 29 28 27 26 25 24 txrxbuf_zct_rx2 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_zct_rx2 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_zct_rx2 (15:8) 76543210 txrxbuf_zct_rx2 (7:0) 31 30 29 28 27 26 25 24 txrxbuf_zct_rx3 (31:24) 23 22 21 20 19 18 17 16 txrxbuf_zct_rx3 (23:16) 15 14 13 12 11 10 9 8 txrxbuf_zct_rx3 (15:8) 76543210 txrxbuf_zct_rx3 (7:0)
510 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.8 other registers 27.8.3.8.1 phy layer timer register name: timer_beacon_ref address: 0xfe47 - 0xfe4a access: read-only reset: 0x00000000 timer for the physical layer, which consists of a free-running clock measured in 10 s steps. it indefinitely increases a unit each 10 s, overflowing back to 0. it is set by hardware and is a read-only register. this register is used by the physical layer for being in accordance with prime specification. 31 30 29 28 27 26 25 24 timer_beacon_ref (31:24) 23 22 21 20 19 18 17 16 timer_beacon_ref (23:16) 15 14 13 12 11 10 9 8 timer_beacon_ref (15:8) 76543210 timer_beacon_ref (7:0)
511 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.8.2 phy layer error counter register name: phy_errors address: 0xfe94 access: read/write reset: 0x00 the system stores in these bits the number of times that a physical layer error has occurred. this counter can be cleared to zero. the value stored in this register is cleared every time the register is read. 76543210 - - - phy_errors
512 sam4cp [datasheet] 43051e?atpl?08/14 27.8.3.8.3 system configuration register name: sys_config address: 0xfe2c access: read/write reset: 0x04 ? conv_pd: converter power down microcontroller can activate internal converter power down mode by setting this bit. when internal converter is in power down mode, the system is unable to receive. this bit is high-level active. ? phy_rst: physical layer reset this bit resets the physical layer. to perform a physical layer reset cycle, microcontroller must set this bit to ?1? and then must clear it to ?0?. 76543210 - --- conv_pd - - phy_rst
513 sam4cp [datasheet] 43051e?atpl?08/14 28. peripheral dma controller (pdc) 28.1 description the peripheral dma controller (pdc) tran sfers data between on-chip serial peripherals and the target memories. the link between the pdc and a serial peripheral is operated by the ahb to apb bridge. the user interface of each pdc channel is integrated into the user interface of the peripheral it serves. the user interface of mono-directional channels (receive-only or transmit-only), contains two 32-bit memory pointers and two 16-bit counters, one set (pointer, counter) for the current transfer and one set (pointer, counter) for the next transfer. the bidirectional channel user interface contains four 32-bit memory pointers and four 16-bit counters. each set (pointer, counter) is used by the current transmit, next transmit, current receive and next receive. using the pdc decreases processor overhead by reducing its intervention during the transfer. this lowers significantly the number of clock cycles required for a data transfer, improving microcontroller performance. to launch a transfer, the peripheral tr iggers its associated pdc channels by using transmit and receive signals. when the programmed data is transferred, an end of transfer interrupt is generated by the peripheral itself. 28.2 embedded characteristics ? performs transfers to/from apb communication serial peripherals ? supports half-duplex and full-duplex peripherals
514 sam4cp [datasheet] 43051e?atpl?08/14 28.3 block diagram figure 28-1. block diagram 28.4 functional description 28.4.1 configuration the pdc channel user interface enables the user to configure and control data transfers for each channel. the user interface of each pdc channel is integrated into the associated peripheral user interface. the user interface of a serial peripheral, whether it is full- or half-duplex, contains four 32-bit pointers (rpr, rnpr, tpr, tnpr) and four 16-bit counter registers (rcr, rncr, tcr, tncr). however, the transmit and receive parts of each type are programmed differently: the transmit and receive parts of a full duplex peripheral can be programmed at the same time, whereas only one part (transmit or receive) of a half duplex peripheral can be programmed at a time. pdc full duplex peripheral thr rhr pdc channel a pdc channel b control status & control control pdc channel c half duplex peripheral thr status & control receive or transmit peripheral rhr or thr control control rhr pdc channel d status & control
515 sam4cp [datasheet] 43051e?atpl?08/14 32-bit pointers define the access location in memory for the current and next transfer, whether it is for read (transmit) or write (receive). 16-bit counters define the size of the current and next transfers. it is possible, at any moment, to read the number of transfers remaining for each channel. the pdc has dedicated status registers which indicate if the transfer is enabled or disabled for each channel. the status for each channel is located in the associated peripheral status register. transfers can be enabled and/or disabled by setting txten/txtdis and rxten/rxtdis in the peripheral?s transfer control register. at the end of a transfer, the pdc channel sends status flag s to its associated peripheral. these flags are visible in the peripheral status register (endrx, endtx, rxbuff, and txbufe). refer to section 28.4.3 and to the associated peripheral user interface. the peripheral where a pdc transfer is configured must have its peripheral clock enabled. the peripheral clock must be also enabled to access the pdc register set associated to this peripheral. 28.4.2 memory pointers each full-duplex peripheral is connected to the pdc by a receive channel and a transmit channel. both channels have 32-bit memory pointers that point to a receive area and to a transmit area, respectively, in the target memory. each half-duplex peripheral is connected to the pdc by a bidirectional channel. this channel has two 32-bit memory pointers, one for current transfer and the other for next transfer. these pointers point to transmit or receive data depending on the operating mode of the peripheral. depending on the type of transfer (byte, half-word or word), the memory pointer is incremented respectively by 1, 2 or 4 bytes. if a memory pointer address changes in the middle of a transfer, the pdc channel continues operating using the new address. 28.4.3 transfer counters each channel has two 16-bit counters, one for the current transfer and the other one for the next transfer. these counters define the size of data to be transferred by the channel. the current transfer counter is decremented first as the data addressed by current memory pointer starts to be transferred. when the current transfer counter reaches zero, the channel checks its next transfer counter. if the value of the next counter is zero, the channel stops transferring data and sets the appropriate flag. if the next counter value is greater than zero, the values of the next pointer/next counter are copied into the current pointer/current counter and the channel resumes the transfer, whereas next pointer/next counter get zero/zero as values. at the end of this transfer the pdc channel sets the ap propriate flags in the peripheral status register. the following list gives an overview of how status register flags behave depending on the counters values: ? endrx flag is set when the pdc receive counter register (periph_rcr) reaches zero. ? rxbuff flag is set when both periph_rcr and the pdc receive next counter register (periph_rncr) reach zero. ? endtx flag is set when the pdc transmit counter register (periph_tcr) reaches zero. ? txbufe flag is set when both periph_tcr and the pdc transmit next counter register (periph_tncr) reach zero. these status flags are described in the transfer status register (periph_ptsr). 28.4.4 data transfers the serial peripheral triggers its associated pdc channels ? transfers using transmit enable (txen) and receive enable (rxen) flags in the transfer control register integrated in the peripheral?s user interface. when the peripheral receives an external data, it sends a receive ready signal to its pdc receive channel which then requests access to the matrix. when access is granted, the pdc receive channel starts reading the peripheral receive holding register (rhr). the read data are stored in an internal buffer and then written to memory.
516 sam4cp [datasheet] 43051e?atpl?08/14 when the peripheral is about to send data, it sends a t ransmit ready to its pdc transmit channel which then requests access to the matrix. when access is granted, the pdc transmit channel reads data from memory and transfers the data to the transmit holding register (thr) of its associ ated peripheral. the same peripheral sends data depending on its mechanism. 28.4.5 pdc flags and peripheral status register each peripheral connected to the pdc sends out receive ready and transmit ready flags and the pdc returns flags to the peripheral. all these flags are only visible in the peripheral status register. depending on whether the peripheral is half- or full-duplex, the flags belong to either one single channel or two different channels. 28.4.5.1 receive transfer end the receive transfer end flag is set when periph_rcr reaches zero and the last data has been transferred to memory. this flag is reset by writing a non-zero value to periph_rcr or periph_rncr. 28.4.5.2 transmit transfer end the transmit transfer end flag is set when periph_tcr reaches zero and the last data has been written to the peripheral thr. this flag is reset by writing a non-zero value to periph_tcr or periph_tncr. 28.4.5.3 receive buffer full the receive buffer full flag is set when periph_rcr reaches zero, with periph_rncr also set to zero and the last data transferred to memory. this flag is reset by writing a non-zero value to periph_tcr or periph_tncr. 28.4.5.4 transmit buffer empty the transmit buffer empty flag is set when periph_tcr reaches zero, with periph_tncr also set to zero and the last data written to peripheral thr. this flag is reset by writing a non-zero value to periph_tcr or periph_tncr. 28.5 peripheral dma controller (pdc) user interface note: 1. periph: ten registers are mapped in the peripheral memory space at the same offset. these can be defined by the user depending on the function and the desired peripheral. table 28-1. register mapping offset register name access reset 0x00 receive pointer register periph (1) _rpr read/write 0 0x04 receive counter register periph_rcr read/write 0 0x08 transmit pointer register periph_tpr read/write 0 0x0c transmit counter register periph_tcr read/write 0 0x10 receive next pointer register periph_rnpr read/write 0 0x14 receive next counter register periph_rncr read/write 0 0x18 transmit next pointer register periph_tnpr read/write 0 0x1c transmit next counter register periph_tncr read/write 0 0x20 transfer control register periph_ptcr write-only 0 0x24 transfer status register periph_ptsr read-only 0
517 sam4cp [datasheet] 43051e?atpl?08/14 28.5.1 receive pointer register name: periph_rpr access: read/write ? rxptr: receive pointer register rxptr must be set to receive buffer address. when a half-duplex peripheral is connected to the pdc, rxptr = txptr. 31 30 29 28 27 26 25 24 rxptr 23 22 21 20 19 18 17 16 rxptr 15 14 13 12 11 10 9 8 rxptr 76543210 rxptr
518 sam4cp [datasheet] 43051e?atpl?08/14 28.5.2 receive counter register name: periph_rcr access: read/write ? rxctr: receive counter register rxctr must be set to receive buffer size. when a half-duplex peripheral is connected to the pdc, rxctr = txctr. 0 = stops peripheral data transfer to the receiver 1 - 65535 = starts peripheral data transfer if the corresponding channel is active 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rxctr 76543210 rxctr
519 sam4cp [datasheet] 43051e?atpl?08/14 28.5.3 transmit pointer register name: periph_tpr access: read/write ? txptr: transmit counter register txptr must be set to transmit buffer address. when a half-duplex peripheral is connected to the pdc, rxptr = txptr. 31 30 29 28 27 26 25 24 txptr 23 22 21 20 19 18 17 16 txptr 15 14 13 12 11 10 9 8 txptr 76543210 txptr
520 sam4cp [datasheet] 43051e?atpl?08/14 28.5.4 transmit counter register name: periph_tcr access: read/write ? txctr: transmit counter register txctr must be set to transmit buffer size. when a half-duplex peripheral is connected to the pdc, rxctr = txctr. 0 = stops peripheral data transfer to the transmitter. 1- 65535 = starts peripheral data transfer if the corresponding channel is active. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txctr 76543210 txctr
521 sam4cp [datasheet] 43051e?atpl?08/14 28.5.5 receive next pointer register name: periph_rnpr access: read/write ? rxnptr: receive next pointer rxnptr contains the next receive buffer address. when a half-duplex peripheral is connected to the pdc, rxnptr = txnptr. 31 30 29 28 27 26 25 24 rxnptr 23 22 21 20 19 18 17 16 rxnptr 15 14 13 12 11 10 9 8 rxnptr 76543210 rxnptr
522 sam4cp [datasheet] 43051e?atpl?08/14 28.5.6 receive next counter register name: periph_rncr access: read/write ? rxnctr: receive next counter rxnctr contains the next receive buffer size. when a half-duplex peripheral is connected to the pdc, rxnctr = txnctr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rxnctr 76543210 rxnctr
523 sam4cp [datasheet] 43051e?atpl?08/14 28.5.7 transmit next pointer register name: periph_tnpr access: read/write ? txnptr: transmit next pointer txnptr contains the next transmit buffer address. when a half-duplex peripheral is connected to the pdc, rxnptr = txnptr. 31 30 29 28 27 26 25 24 txnptr 23 22 21 20 19 18 17 16 txnptr 15 14 13 12 11 10 9 8 txnptr 76543210 txnptr
524 sam4cp [datasheet] 43051e?atpl?08/14 28.5.8 transmit next counter register name: periph_tncr access: read/write ? txnctr: transmit counter next txnctr contains the next transmit buffer size. when a half-duplex peripheral is connected to the pdc, rxnctr = txnctr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txnctr 76543210 txnctr
525 sam4cp [datasheet] 43051e?atpl?08/14 28.5.9 transfer control register name: periph_ptcr access: write-only ? rxten: receiver transfer enable 0 = no effect. 1 = enables pdc receiver channel requests if rxtdis is not set. when a half-duplex peripheral is connected to the pdc, enabling the receiver channel requests automatically disables the transmitter channel requests. it is forbidden to set both txten and rxten for a half-duplex peripheral. ? rxtdis: receiver transfer disable 0 = no effect. 1 = disables the pdc receiver channel requests. when a half-duplex peripheral is connected to the pdc, disabling the receiver channel requests also disables the transmitter channel requests. ? txten: transmitter transfer enable 0 = no effect. 1 = enables the pdc transmitter channel requests. when a half-duplex peripheral is connected to the pdc, it enables the transmitter channel requests only if rxten is not set. it is forbidden to set both txten and rxten for a half-duplex peripheral. ? txtdis: transmitter transfer disable 0 = no effect. 1 = disables the pdc transmitter channel requests. when a half-duplex peripheral is connected to the pdc, disabling the transmitter channel requests disables the receiver channel requests. 31 30 29 28 27 26 25 24 ??????? ? 23 22 21 20 19 18 17 16 ???? ???? 15 14 13 12 11 10 9 8 ? ? ? ? ? ? txtdis txten 76543210 ? ? ? ? ? ? rxtdis rxten
526 sam4cp [datasheet] 43051e?atpl?08/14 28.5.10 transfer status register name: periph_ptsr access: read-only ? rxten: receiver transfer enable 0 = pdc receiver channel requests are disabled. 1 = pdc receiver channel requests are enabled. ? txten: transmitter transfer enable 0 = pdc transmitter channel requests are disabled. 1 = pdc transmitter channel requests are enabled. 31 30 29 28 27 26 25 24 ??????? ? 23 22 21 20 19 18 17 16 ????? ? ? ? 15 14 13 12 11 10 9 8 ??????? txten 76543210 ??????? rxten
527 sam4cp [datasheet] 43051e?atpl?08/14 29. clock generator 29.1 description the clock generator user interface is embedded within the power management controller and is described in section 30.18 ?power management controller (pmc) user interface? . however, the clock generator registers are named ckgr_. 29.2 embedded characteristics the clock generator is made up of: ? a low power 32768 hz slow clock oscillator with bypass mode. ? a low power rc oscillator. ? a 3 to 20 mhz crystal or ceramic resonator-based oscillator, which can be bypassed. ? a factory programmed fast rc oscillator. three output frequencies can be selected: 4/8/12 mhz. by default 4 mhz is selected. ? two programmable plls, (plla input from 32 khz, output clock range 8 mhz and pllb input from 3 to 32 mhz, output clock range 80 to 240 mhz), capable of providing the clock mck to the processor and to the peripherals. it provides the following clocks: ? slck, the slow clock, which is the only permanent clock within the system. ? mainck is the output of the main clock oscillator selection: either the crystal or ceramic resonator-based oscillator or 4/8/12 mhz fast rc oscillator. ? pllack is the output of the 8 mhz programmable pll (plla). ? pllbck is the output of the divider and 80 to 240 mhz programmable pll (pllb).
528 sam4cp [datasheet] 43051e?atpl?08/14 29.3 block diagram figure 29-1. clock generator block diagram 29.4 slow clock the supply controller embeds a slow clock generator that is supplied with the vddbu power supply. as soon as the vddbu is supplied, both the crystal oscillator and the embedded rc oscillator are powered up, but only the embedded rc oscillator is enabled. this allows the slow clock to be valid in a short time (about 100 s). the slow clock is generated either by the slow clock crystal oscillator or by the slow clock rc oscillator. the selection between the rc or the crystal oscillator is made by writing the xtalsel bit in the supply controller control register (supc_cr). 29.4.1 slow clock rc oscillator by default, the slow clock rc oscillator is enabled and selected. the user has to take into account the possible drifts of the rc oscillator. more details are given in the section ?dc characteristics? of the product datasheet. it can be disabled via the xtalsel bit in the supc_cr. plla pllb and divider /2 plladiv2 pllbdiv2 main clock mainck plla clock pllack control status xin xout xin32 xout32 slck xtalsel (supply controller) pllb clock pllbck 0 1 0 1 3-20 mhz crystal or ceramic resonator oscillator embedded 4/8/12 mhz fast rc oscillator 32768 hz crystal oscillator embedded 32 khz rc oscillator srcb 1 0 clock generator slow clock power management controller ckgr_pllbr pmc_mckr moscsel ckgr_mor pmc_mckr
529 sam4cp [datasheet] 43051e?atpl?08/14 29.4.2 slow clock crystal oscillator the clock generator integrates a 32768 hz low-power oscillator. to use this oscillator, the xin32 and xout32 pins must be connected to a 32768 hz crystal. two external capacitors must be wired as shown in figure 29-2 . more details are given in the section ?dc characteristics? of the product datasheet. note that the user is not obliged to use the slow clock crystal and can use the rc oscillator instead. figure 29-2. typical slow clock crystal oscillator connection the user can select the crystal oscillator to be the source of the slow clock, as it provides a more accurate frequency. the command is made by writing the supc_cr with the xtalsel bit at 1. this results in a sequence which enables the crystal oscillator and then disables the rc oscillator to save power. the switch of the slow clock source is glitch free. the oscsel bit of the supply controller status register (supc_sr) or the oscsel bit of the pmc status register (pmc_sr) tracks the oscillator frequency downstream. it must be read in order to be informed when the switch sequence, initiated when a new value is written in the xtalsel bit of supc_cr, is done. coming back on the rc oscillator is only possible by shutting down the vddbu power supply. if the user does not need the crystal oscillator, the xin32 and xout32 pins can be left unconnected. the user can also set the crystal oscillator in bypass mode instead of connecting a crystal. in this case, the user has to provide the external clock signal on xin32. the input characteristics of the xin32 pin are given in the product electrical characteristics section. in order to set the bypass mode, the oscbypass bit of the supply controller mode register (supc_mr) needs to be set at 1. the user can set the slow clock crystal oscillator in bypass mode instead of connecting a crystal. in this case, the user has to provide the external clock signal on xin32. the input characteristics of the xin32 pin under these conditions are given in the product electrical characteristics section. the programmer has to be sure to set the oscbypass bit in the supc_mr and xtalsel bit in the supc_cr. xin32 xout32 gnd 32768 hz crystal
530 sam4cp [datasheet] 43051e?atpl?08/14 29.5 main clock figure 29-3 shows the main clock block diagram. figure 29-3. main clock block diagram the main clock has two sources: ? 4/8/12 mhz fast rc oscillator which starts very quickly and is used at startup. ? 3 to 20 mhz crystal or ceramic resonator-based oscillator which can be bypassed. 29.5.1 fast rc oscillator after reset, the 4/8/12 mhz fast rc oscillator is enabled with the 4 mhz frequency selected and it is selected as the source of mainck. mainck is the default clock selected to start up the system. the fast rc oscillator frequencies are calibrated in production except the lowest frequency which is not calibrated. refer to the ?dc characteristics? section of the product datasheet. xin xout moscxten moscxtst moscxts main clock frequency counter mainf slck slow clock 3-20 mhz crystal or ceramic resonator oscillator 3-20 mhz oscillator counter moscrcen fast rc oscillator moscrcs moscrcf moscrcen moscxten moscsel moscsel moscsels 1 0 mainck main clock mainck main clock ref. rcmeas ckgr_mcfr ckgr_mor ckgr_mor ckgr_mor pmc_sr pmc_sr ckgr_mor ckgr_mor ckgr_mor ckgr_mor ckgr_mor ckgr_mcfr pmc_sr ckgr_mcfr mainfrdy
531 sam4cp [datasheet] 43051e?atpl?08/14 the software can disable or enable the 4/8/12 mhz fast rc oscillator with the moscrcen bit in the clock generator main oscillator register (ckgr_mor). the user can also select the output frequency of the fast rc oscillator, either 4/8/12mhz are available. it can be done through moscrcf bits in ckgr_mor. when changing this frequency selection, the moscrcs bit in the power management controller status register (pmc_sr) is automatically cleared and mainck is stopped until the oscillator is stabilized. once the oscillator is stabilized, mainck restarts and moscrcs is set. when disabling the main clock by clearing the moscrcen bit in ckgr_mor, the moscrcs bit in pmc_sr is automatically cleared, indicating the main clock is off. setting the moscrcs bit in the power management controller interrupt enable register (pmc_ier) can trigger an interrupt to the processor. when main clock (mainck) is not used to drive the processor and frequency monitor (slck or pllack is used instead), it is recommended to disable the main oscillators. the cal4, cal8 and cal12 values in the pmc oscillator calibration register (pmc_ocr) are the default values set by atmel during production. these values are stored in a specific flash memory area different from the main memory plane. these values cannot be modifi ed by the user and cannot be erased by a flash erase c ommand or by the erase pin. values written by the user's application in pmc_ocr are reset after each power up or peripheral reset. 29.5.2 fast rc oscillator clock frequency adjustment it is possible for the user to adjust the main rc oscillator frequency through pmc_ocr. by default, sel 4/8/12 are low, so the rc oscillator will be driven with flash calibration bits which are programmed during chip production. the user can adjust the trimming of the 4/8/12 mhz fast rc oscillator through this register in order to obtain more accurate frequency (to compensate derating factors such as temperature and voltage). in order to calibrate the oscillator lower frequency, sel4 must be set to 1 and a good frequency value must be configured in cal4. likewise, sel8/12 must be set to 1 and a trim value must be configured in cal8/12 in order to adjust the other frequencies of the oscillator. it is possible to adjust the oscillator frequency while operating from this clock. for example, when running on lowest frequency it is possible to change the cal4 value if sel4 is set in pmc_ocr. it is possible to restart, at anytime, a measurement of the main frequency by means of the rcmeas bit in main clock frequency register (ckgr_mcfr). thus, when mainfrdy flag reads 1, another read access on ckgr_mcfr provides an image of the frequency of the main clock on mainf field. the software can calculate the error with an expected frequency and correct the cal4 (or cal8/cal12) field accordingly. this may be used to compensate frequency drift due to derating factors such as temperature and/or voltage. 29.5.3 3 to 20 mhz crystal or ceramic resonator-based oscillator after reset, the 3 to 20 mhz crystal or ceramic resonator-based oscillator is disabled and it is not selected as the source of mainck. the user can select the 3 to 20 mhz crystal or ceramic resonator-based oscillat or to be the source of mainck, as it provides a more accurate frequency. the software enables or disables the main oscillator in order to reduce power consumption by clearing the moscxten bit in ckgr_mor. when disabling the main oscillator by clearing the moscxten bit in ckgr_mor, the moscxts bit in pmc_sr is automatically cleared, indicating the main clock is off. when enabling the main oscillator, the user must initiate the main oscillator counter with a value corresponding to the start-up time of the oscillator. this start-up time depends on the crystal frequency connected to the oscillator. when the moscxten bit and the moscxtst are written in ckgr_mor to enable the main oscillator, the xin and xout pins are automatically switched into oscillator mode and moscxts bit in pmc_sr is cleared and the counter starts counting down on the slow clock divided by 8 from the moscxtst value. since the moscxtst value is coded with 8 bits, the maximum start-up time is about 62 ms.
532 sam4cp [datasheet] 43051e?atpl?08/14 when the counter reaches 0, the moscxts bit is set, indicating that the main clock is valid. setting the moscxts bit in the interrupt mask register (pmc_imr) can trigger an interrupt to the processor. 29.5.4 main clock oscillator selection the user can select the source of the main clock from either the 4/8/12 mhz fast rc oscillator, the 3 to 20 mhz crystal or ceramic resonator-based oscillator. the advantage of the 4/8/12 mhz fast rc oscillator is its fast start-up time. by default, this oscillator is selected to start the system and when entering wait mode. the advantage of the 3 to 20 mhz crystal or ceramic resonator-based oscillator is the high level of accuracy provided. the selection of the oscillator is made by writing the moscsel bit in ckgr_mor. the switch of the main clock source is glitch free, so there is no need to run out of slck, pllack or pllbck in order to change the selection. the moscsels bit of pmc_sr indicates when the switch sequence is done. setting the moscsels bit in pmc_imr can trigger an interrupt to the processor. enabling the fast rc oscillator (moscrcen = 1) and changing the fast rc frequency (mosccrf) at the same time is not allowed. the fast rc must be enabled first and its frequency changed in a second step. 29.5.5 switching main clock between the main rc oscillator and fast crystal oscillator both sources must be enabled during the switchover operation. only after completion can the unused oscillator be disabled. if switching to fast crystal oscillator, the clock presence must first be checked according to what is described in section 29.5.6 ?software sequence to detect the presence of fast crystal? because the source may not be reliable (crystal failure or bypass on a non-existent clock). 29.5.6 software sequence to detect the presence of fast crystal the frequency meter carried on ckgr_mcfr is operating on the selected main clock and not on the fast crystal clock nor on the fast rc oscillator clock. therefore, to check for the presence of the fast crystal clock, it is necessary to have the main clock (mainck) driven by the fast crystal clock (moscsel=1). the following software sequence order must be followed: ? mck must select the slow clock (css=0 in the master clock register (pmc_mckr)). ? wait for the mckrdy flag in pmc_sr to be 1. ? the fast crystal must be enabled by programming 1 in the moscxten field in the ckgr_mor register with the moscxtst field being programmed to the appropriate value (see the electrical characteristics chapter). ? wait for the moscxts flag to be 1 in pmc_sr to get the end of a start-up period of the fast crystal oscillator. ? then, moscsel must be programmed to 1 in ckgr_mor to select fast main crystal oscillator for the main clock. ? moscsel must be read until its value equals 1. ? then the moscsels status flag must be checked in pmc_sr. at this point, 2 cases may occur (either moscsels = 0 or moscsels = 1). ? if moscsels = 1, there is a valid crystal connected and its frequency can be determined by initiating a frequency measure by programming rcmeas in ckgr_mcfr. ? if moscsels = 0, there is no fast crystal clock (either no crystal connected or a crystal clock out of specification). a frequency measure can reinforce this status by initiating a frequency measure by programming rcmeas in ckgr_mcfr. ? if moscsels=0, the selection of the main clock must be programmed back to the main rc oscillator by writing moscsel to 0 prior to disabling the fast crystal oscillator. ? if moscsels=0, the crystal oscillator can be disabled (moscxten=0 in the ckgr_mor register).
533 sam4cp [datasheet] 43051e?atpl?08/14 29.5.7 main clock frequency counter the device features a main clock frequency counter that provides the frequency of the main clock. the main clock frequency counter is reset and starts incrementing at the main clock speed after the next rising edge of the slow clock in the following cases: ? when the 4/8/12 mhz fast rc oscillator clock is selected as the source of main clock and when this oscillator becomes stable (i.e., when the moscrcs bit is set). ? when the 3 to 20 mhz crystal or ceramic resonator-based oscillator is selected as the source of main clock and when this oscillator becomes stable (i.e., when the moscxts bit is set). ? when the main clock oscillator selection is modified. ? when the rcmeas bit of ckgr_mfcr is written to 1. then, at the 16th falling edge of slow clock, the mainfrdy bit in the clock generator main clock frequency register (ckgr_mcfr) is set and the counter stops counting. its value can be read in the mainf field of ckgr_mcfr and gives the number of main clock cycles during 16 periods of slow clock, so that the frequency of the 4/8/12 mhz fast rc oscillator or 3 to 20 mhz crystal or ceramic resonator-based oscillator can be determined. 29.6 divider and pll blocks the device features one divider/two pll blocks that permit a wide range of frequencies to be selected on either the master clock, the processor clock or the programmable clock outputs. figure 29-4 shows the block diagram of the divider and pll blocks. figure 29-4. divider and pll blocks diagram divider b divb pll b mulb pll a counter pllbcount lockb pll a counter pllacount locka mula slck pllack pllbck pll b mainck pllbdiv2 srcb 0 1 slck plladiv2 ckgr_pllbr ckgr_pllar ckgr_pllar ckgr_pllbr ckgr_pllbr pmc_sr pmc_sr pmc_mckr pmc_mckr ckgr_pllbr
534 sam4cp [datasheet] 43051e?atpl?08/14 29.6.1 divider and phase lock loop programming the divider can be set between 1 and 255 in steps of 1. when a divider field (div) is set to 0, the output of the corresponding divider and the pll output is a continuous signal at level 0. on reset, each div field is set to 0, thus the corresponding pll input clock is set to 0. the plls (plla, pllb) allow multiplication of the slck clock source for plla or plla output clock or mainck divided output for pllb. the pll clock signal has a frequency that depends on the respective source signal frequency and on the parameters div (divb) and mul (mula, mulb). the factor applied to the source signal frequency is (mul + 1)/div. when mul is written to 0 or pllaen=0, the pll is disabled and its power consumption is saved. re-enabling the pll can be performed by writing a value higher than 0 in the mul field and pllaen higher than 0. to change the frequency of the plla, the plla must be first disabled by writing 0 in mula field and 0 in pllacount field. then, the plla can be configured to generate the new frequency by programming a new multiplier in mula and the pllacount field in the same register access. see electrical characteristics to get the pllacount values covering the pll transient time. whenever the pll is re-enabled or one of its parameters is changed, the lock (locka, lockb) bit in pmc_sr is automatically cleared. the values written in the pllcount field (pllacount, pllbcount) in ckgr_pllr (ckgr_pllar, ckgr_pllbr) are loaded in the pll counter. the pll counter then decrements at the speed of the slow clock until it reaches 0. at this time, the lock bit is set in pmc_sr and can trigger an interrupt to the processor. the user has to load the number of slow clock cycles required to cover the pll transient time into the pllcount field. the pll clock can be divided by 2 by writing the plldiv2 (plladiv2, pllbdiv2) bit in pmc master clock register (pmc_mckr). the plladiv2 has no effect on pllb clock input because the output of the plla is directly routed to pllb input selection. it is prohibited to change the 4/8/12 mhz fast rc oscillator, or the main oscillator selection in ckgr_mor while the master clock source is the pll and the pll reference clock is the fast rc oscillator. the user must: ? switch on the main rc oscillator by writing a 1 to the css field of pmc_mckr. ? change the frequency (moscrcf) or oscillator selection (moscsel) in ckgr_mor. ? wait for moscrcs (if frequency changes) or moscsels (if oscillator selection changes) in pmc_sr. ? disable and then enable the pll (lockx in pmc_idr and pmc_ier). ? wait for the lock flag in pmc_sr. ? switch back to the pll by writing the appropriate value to the css field of pmc_mckr.
535 sam4cp [datasheet] 43051e?atpl?08/14 30. power management controller (pmc) 30.1 description the power management controller (pmc) optimizes power consumption by controlling all system and user peripheral clocks. the pmc enables/disables the clock inputs to many of the peripherals and the cortex-m4 processor. the supply controller selects between the 32 khz rc oscillator or the slow crystal oscillator. the unused oscillator is disabled automatically so that power consumption is optimized. by default, at startup the chip runs out of the master clock using the fast rc oscillator running at 4 mhz. the user can trim the 8 and 12 mhz rc oscillator frequencies by software. 30.2 embedded characteristics the power management controller provides the following clocks: ? mck, the master clock, programmable from a few hundred hz to the maximum operating frequency of the device. it is available to the modules running permanently, such as the enhanced embedded flash controller. ? processor clock (hclk) and coprocessor (second processor) clock (cphclk), automatically switched off when entering the processor in sleep mode. ? free running processor clock (fclk) and free running coprocessor clock (cpfclk). ? one systick external clock for each cortex-m4 core. ? peripheral clocks, provided to the embedded peripherals (usart, spi, twi, tc, etc.) and independently controllable. ? programmable clock outputs (pckx), selected from the clock generator outputs to drive the device pck pins. ? register write protection. the power management controller also provides the following operations on clocks: ? a main crystal oscillator clock failure detector. ? a 32768 hz crystal oscillator frequency monitor. ? a frequency counter on main clock and an on-the-fly adjustable main rc oscillator frequency.
536 sam4cp [datasheet] 43051e?atpl?08/14 30.3 block diagram figure 30-1. general clock block diagram plla pllb and divider /2 plladiv2 pllbdiv2 management controller main clock mainck control status xin xout xin32 xout32 slck xtalsel (supply controller) 0 1 0 1 3-20 mhz crystal or ceramic resonator oscillator embedded 4/8/12 mhz fast rc oscillator 32768 hz crystal oscillator embedded 32 khz rc oscillator srcb 1 0 clock generator slow clock power periph_clk[n] int slck mainck pllack prescaler / 1,/2,/3,/4,/8, /16,/32,/64 processor clock controller sleep mode master clock controller (pmc_mckr) peripherals clock controller (pmc_pcerx / pmc_pcr) pllbck core 0 (cm4-p0 clock system) c o r e 0 ( c m 4 - p 0 c l o c k s y s t e m ) core 1 (cm4-p1 clock system) c o r e 1 ( c m 4 - p 1 c l o c k s y s t e m ) pres css on/off on/off on/off periph_clk[n+1] periph_clk[n+2] slck mainck pllack prescaler divide by 1 to 16 master clock controller (pmc_mckr) pllbck cppres cpcss on/off periph_clk[m+2] int coprocessor clock cphclk where m is an index for the coprocessor system peripherals cpfclk coprocessor free running clock coprocessor systick clock cpsystick divider / 8 divider / 8 mck pmc_scer/scdr cpck= on/off where n is an index for the processor system peripherals on/off periph_clk[m] coprocessor bus master clock cpbmck processor clock hclk fclk processor free running clock processor systick clock systick processor bus master clock mck pmc_scer/scdr cpbmck= on/off coprocessor clock controller sleep mode pllb clock pllbck plla clock pllack pmc_mckr pmc_mckr moscsel ckgr_mor ckgr_pllbr
537 sam4cp [datasheet] 43051e?atpl?08/14 30.4 master clock controller the master clock controller provides selection and divisi on of the master clock (mck) and coprocessor master clock (cpmck). mck is the clock provided to all the peripherals in the sub-system 0 and cpmck is the clock provided to all peripherals in the sub-system 1). the master clock is selected from one of the clocks provided by the clock generator. selecting the slow clock provides a slow clock signal to the whole device. selecting the main clock saves power consumption of the plls. the master clock controller is made up of a clock selector and a prescaler. the master clock selection is made by writing the css/cpcss field (clock source selection/coprocessor clock source selection) in pmc_mckr (master clock register). the prescaler supports the division by a power of 2 of the selected clock between 1 and 64, and the division by 3. the pres/cppres field in pmc_mckr programs the prescaler. each time pmc_mckr is written to define a new master clock, the mckrdy bit is cleared in pmc_sr. it reads 0 until the master clock is established. then, the mckrdy bit is set and can trigger an interrupt to the processor. this feature is useful when switching from a high speed clock to a lower one to inform the software when the change is actually done. figure 30-2. master clock controller 30.5 processor clock controller the pmc features a processor clock controller (hclk) and a coprocessor clock controller (cphclk) that implements the processor sleep mode. the processor clocks can be disabled by executing the wfi (waitforinterrupt) processor instruction. the processor clock controller (hclk) is enabled after a reset and is automatically re-enabled by any enabled interrupt. the coprocessor clock controller (cphclk) is disabled after reset. it is up to the master application to enable the cphclk. similar to hclk, cphclk is automatically re-enabled by any enabled instruction after having executed a wfi instruction. the processor sleep mode is entered by disabling the processor clock, which is automatically re-enabled by any enabled fast or normal interrupt, or by the reset of the product. when processor sleep mode is entered, the current instruction is finished before the clock is stopped, but this does not prevent data transfers from other masters of the system bus. 30.6 systick clock the systick calibration value is fixed to 8000 which allows th e generation of a time base of 1 ms with systick clock to the maximum frequency on mck divided by 8. 30.7 peripheral clock controller the power management controller controls the clocks of ea ch embedded peripheral by means of the peripheral clock controller. the user can individually enable and disable the clock on the peripherals. the user can also enable and disable these clocks by writing peripheral clock enable 0 (pmc_pcer0), peripheral clock disable 0 (pmc_pcdr0), peripheral clock enable 1 (pmc_pcer1) and peripheral clock disable 1 (pmc_pcdr1) registers. the status of the peripheral clock activity can be read in the peripheral clock status register (pmc_pcsr0) and peripheral clock status register (pmc_pcsr1). slck master clock prescaler to the mck divider pres css m ainck p llack p llbck to the processor clock controller (pck) pmc_mckr pmc_mckr
538 sam4cp [datasheet] 43051e?atpl?08/14 if the peripherals located on the coprocessor system bus require data exchange with the co-processor or the main processor, the cpbmck clock must be enabled prior to enable any co-processor peripheral clock. when a peripheral clock is disabled, the clock is immediately stopped. the peripheral clocks are automatically disabled after a reset. to stop a peripheral, it is recommended that the system software wait until the peripheral has executed its last programmed operation before disabling the clock. this is to avoid data corruption or erroneous behavior of the system. the bit number within the peripheral clock control registers (pmc_pcer0-1, pmc_pcdr0-1, and pmc_pcsr0-1) is the peripheral identifier defined at the product level. the bit number corresponds to the interrupt source number assigned to the peripheral. 30.8 free running processor clock the free running processor clock (fclk) together with the free running coprocessor master clock (cpfclk) used for sampling interrupts and clocking debug blocks ensures that interrupts can be sampled, and sleep events can be traced, while the processor(s) is(are) sleeping. it is connected to master clock (mck)/coprocessor master clock (cpmck). 30.9 programmable clock output controller the pmc controls 3 signals to be output on external pins, pckx. each signal can be independently programmed via the programmable clock registers (pmc_pckx). pckx can be independently selected between the slow clock (slck), the main clock (mainck), the plla clock (pllack), the pllb clock (pllbck), and the master clock (mck) by writing the css field in pmc_pckx. each output signal can also be divided by a power of 2 between 1 and 64 by writing the pres (prescaler) field in pmc_pckx. each output signal can be enabled and disabled by writing 1 in the corresponding bit, pckx of pmc_scer and pmc_scdr, respectively. status of the active programmable out put clocks are given in th e pckx bits of pmc_scsr (system clock status register). pckrdyx status flag in pmc_sr indicates that the programmable clock is actually what has been programmed in the programmable clock registers. as the programmable clock controller does not manage with glitch prevention when switching clocks, it is strongly recommended to disable the programmable clock before any configuration change and to re-enable it after the change is actually performed. 30.10 main processor fast startup the device allows the main processor to restart in less than 10 microseconds while the device exits wait mode only if the c-code function managing the wait mode entry and exit is linked to and executed from on-chip sram. the fast startup time cannot be achieved if the first instruction after an exit is located in the embedded flash. if fast startup is not required or if the first instruction after a wait mode exit is located in embedded flash, see section 30.11 ?main processor startup from embedded flash? . prior to instructing the device to enter wait mode, the fast rc oscillator must be selected as the master clock source (the css field in pmc_mckr must be written to 1) and the internal sources of wake-up must be cleared. it must be verified that none of the enabled external wake-up inputs (wkup) hold an active polarity. the system enters wait mode either by setting the waitmode bit in ckgr_mor, or by executing the waitforevent (wfe) instruction of the processor while the lpm bit is at 1 in pmc_fsmr. immediately after setting the waitmode bit or using the wfe instruction, wait for the mckrdy bit to be set in pmc_sr. in case of dual core activity, it is recommended to check the coprocessor state before instructing the main processor to enter wait mode.
539 sam4cp [datasheet] 43051e?atpl?08/14 a fast startup is enabled upon the detection of a programmed level on one of the 16 wake-up inputs (wkup) or upon an active alarm from the rtc and rtt. the polarity of the 16 wake-up inputs is programmable by writing the pmc fast startup polarity register (pmc_fspr). the fast startup circuitry, as shown in figure 30-3 , is fully asynchronous and provides a fast startup signal to the power management controller. as soon as the fast startup signal is asserted, the embedded 4/8/12mhz fast rc oscillator restarts automatically. when entering wait mode, the embedded flash can be placed in one of the low-power modes (deep-power-down or standby) depending on the configuration of the flpm field in the pmc_fsmr . the flpm field can be programmed at anytime and its value will be applied to the next wait mode period. the power consumption reduction is optimal when configuring 1 (deep power down mode) in field flpm. if 0 is programmed (standby mode), the power consumption is slightly higher than in deep-power- down mode. when programming 2 in field flpm, the wait mode flash power consumption is equivalent to that of the active mode when there is no read access on the flash. figure 30-3. fast startup circuitry each wake-up input pin and alarm can be enabled to generate a fast startup event by setting the corresponding bit in the pmc_fsmr. the user interface does not provide any status for fast startup, but the user can easily recover this information by reading the pio controller and the status registers of the rtc and rtt. 30.11 main processor startup from embedded flash the inherent start-up time of the embedded flash cannot provide a fast startup of the system. if system fast start-up time is not required, the first instruction after a wait mode exit can be located in the embedded flash. under these conditions, prior to entering wait mode, the flash controller must be programmed to perform access in 0 wait-state (see flash controller section). fast_resta rt w kup15 fstt15 fstp15 wkup1 fstt1 fstp1 wkup0 fstt0 fstp0 rttal rtcal rtt alarm rtc alarm
540 sam4cp [datasheet] 43051e?atpl?08/14 the procedure and conditions to enter wait mode and the circuitry to exit wait mode are strictly the same as fast startup (see section 30.10 ?main processor fast startup? ). 30.12 coprocessor sleep mode the coprocessor enters sleep mode by executing the waitforinterrupt (wfi) instruction of the coprocessor. any enabled interrupt can wake the processor up. 30.13 main clock failure detector the clock failure detector monitors the main crystal oscillator or ceramic resonator-based oscillator to identify an eventual failure of this oscillator. the clock failure detector can be enabled or disabled by bit cfden in ckgr_mor. after a vddcore reset, the detector is disabled. however, if the oscillator is disabled (moscxten = 0), the detector is disabled too. a failure is detected by means of a c ounter incrementing on the main oscillat or clock edge and timing logic clocked on the slow rc oscillator controlling the counter. thus, the slow rc oscillator must be enabled. the counter is cleared when the slow rc oscillator clock signal is low and enabled when the signal is high. thus the failure detection time is 1 slow rc oscillator clock period. if, during the high level period of the slow rc oscillator clock signal, less than 8 fast crystal oscillator clock periods have been counted, then a failure is reported. if a failure of the main oscillator is detected, bit cfdev in pmc_sr indicates a failure event and generates an interrupt if the corresponding interrupt source is enabled. the interrupt remains active until a read occurs in pmc_sr. the user can know the status of the clock failure detection at any time by reading the cfds bit in pmc_sr. figure 30-4. clock failure detection (example) if the main oscillator is selected as the source clock of mainck (moscsel in ckgr_mor = 1), and if the master clock source is pllack or pllbck (css = 2), a clock failure detection automatically forces mainck to be the source clock for the master clock (mck).then, regardless of the pmc configuration, a clock failure detection automatically forces the fast rc oscillator to be the source clock for mainck. if the fast rc oscillator is disabled when a clock failure detection occurs, it is automatically re-enabled by the clock failure detection mechanism. it takes 2 slow clock rc oscillator cycles to detect and switch from the main oscillator, to the fast rc oscillator if the source mck is main clock (mainck), or three slow clock rc oscillator cycles if the source of mck is pllack or pllbck. the user can know the status of the clock failure detector at any time by reading the fos bit in pmc_sr. this fault output remains active until the defect is detected and until it is cleared by the bit foclr in the pmc fault output clear register (pmc_focr). main crystal clock slck note: ratio of clock periods is for illustration purposes only cdfev cdfs read pmc_sr
541 sam4cp [datasheet] 43051e?atpl?08/14 30.14 slow crystal clock frequency monitor the frequency of the slow clock crystal oscillator can be monitored by means of logic driven by the main rc oscillator known as a reliable clock source. this function is enabled by configuring the xt32kfme bit of the ckgr_mor. an error flag (xt32kerr in pmc_sr) is asserted when the slow clock crystal oscillator frequency is out of the +/- 10% nominal frequency value (i.e. 32.768 khz). the error flag can be cleared only if the slow clock frequency monitoring is disabled. when the main rc oscillator frequency is 4 mhz, the accuracy of the measurement is +/-40% as this frequency is not trimmed during production. therefore, +/-10% accuracy is obtained only if the rc oscillator frequency is configured for 8 or 12 mhz. the monitored clock frequency is declared invalid if at least 4 consecutive clock period measurement results are over the nominal period +/-10%. due to the possible frequency variation of the embedded main rc oscillator acting as reference clock for the monitor logic, any slow clock crystal frequency deviation over +/- 10% of the nominal frequency is systematically reported as an error by means of xt32kerr in pmc_sr. between -1% and -10% and +1% and +10%, the error is not systematically reported. thus only a crystal running at 32.768 khz frequency ensures that the error flag will not be asserted. the permitted drift of the crystal is 10000ppm (1%), which allows any standard crystal to be used. if the main rc frequency needs to be changed while the slow clock frequency monitor is operating, the monitoring must be stopped prior to change the main rc frequency. then it can be re-enabled as soon as moscrcs is set in pmc_sr. the error flag can be defined as an interrupt source of the pmc by setting the xt32kerr bit of pmc_ier. 30.15 programming sequence 1. if the fast crystal oscillator is not required, the pll and divider can be directly configured ( step 6. ) else the fast crystal oscillator must be started ( step 2. ). 2. enable the fast crystal oscillator: the fast crystal oscillator is enabled by setting the moscxten field in ckgr_mor. the user can define a start- up time. this can be achieved by writing a value in th e moscxtst field in ckgr_mor. once this register has been correctly configured, the user must wait for moscxts field in pmc_sr to be set. this can be done either by polling moscxts in pmc_sr, or by waiting for the interrupt line to be raised if the associated interrupt source (moscxts) has been enabled in pmc_ier. 3. switch the mainck to the main crystal oscillator by setting moscsel in ckgr_mor. 4. wait for the moscsels to be set in pmc_sr to ensure the switchover is complete. 5. check the main clock frequency: this main clock frequency can be measured via ckgr_mcfr. read ckgr_mcfr until the mainfrdy field is set, after which the user can read the mainf field in ckgr_mcfr by performing an additional read. this provides the number of main clock cycles that have been counted during a period of 16 slow clock cycles. if mainf = 0, switch the mainck to the fast rc oscillator by clearing moscsel in ckgr_mor. if mainf 0, proceed to step 6. 6. set pllx and divider (if not required, proceed to step 7. ): in the names pllx, divx, mulx, lockx, pllxcount, and ckgr_pllxr, ?x? represents a or b. all parameters needed to configure pllx and the divider are located in ckgr_pllxr. the divx field is used to control the divider itself. this parameter can be programmed between 0 and 127. divider output is divider input divided by divx parameter. by default, divx field is set to 0 which means that the divider and pllx are turned off.
542 sam4cp [datasheet] 43051e?atpl?08/14 the mulx field is the pllx multiplier factor. this pa rameter can be programmed between 0 and 250. if mulx is set to 0, pllx will be turned off, otherwise the pllx output frequency is pllx input frequency multiplied by (mulx + 1). the pllxcount field specifies the number of slow clock cycles before the lockx bit is set in the pmc_sr after ckgr_pllxr has been written. once ckgr_pllxr has been written, the user must wait for the lockx bit to be set in the pmc_sr. this can be done either by polling lockx in pmc_sr or by waiting for the interrupt line to be raised if the associated interrupt source (lockx) has been enabled in pmc_ier. all fields in ckgr_pllxr can be programmed in a single write operation. if at some stage one of the following parameters, mulx or divx is modified, the lockx bit goes low to indicate that pllx is not yet ready. when pllx is locked, lockx is set again. the user must wait for the lockx bit to be set before using the pllx output clock. 7. select the master clock and processor clock: the master clock and the processor clock are configurable via pmc_mckr. the css field is used to select the clock source of the master clock and processor clock dividers. by default, the selected clock source is the main clock. the pres field is used to define the processor clock and master clock prescaler. the user can choose between different values (1, 2, 3, 4, 8, 16, 32, 64). prescaler output is the se lected clock source frequency divided by the pres value. once the pmc_mckr has been written, the user must wait for the mckr dy bit to be set in the pmc_sr. this can be done either by polling mckrdy in pmc_sr or by waiting for the interrupt line to be raised if the associated interrupt source (mckrdy) has been enabled in pmc_ier. pmc_mckr must not be programmed in a single write operation. the programming sequence for pmc_mckr is as follows: ? if a new value for css field corresponds to pll clock, ? program the pres field in pmc_mckr. ? wait for the mckrdy bit to be set in pmc_sr. ? program the css field in pmc_mckr. ? wait for the mckrdy bit to be set in pmc_sr. ? if a new value for css field corresponds to main clock or slow clock, ? program the css field in pmc_mckr. ? wait for the mckrdy bit to be set in the pmc_sr. ? program the pres field in pmc_mckr. ? wait for the mckrdy bit to be set in pmc_sr. if at some stage, parameters css or pres are modified, the mckrdy bit goes low to indicate that the master clock and the processor clock are not yet ready. the user must wait for mckrdy bit to be set again before using the master and processor clocks. note: if pllx clock was selected as the master clock and the user decides to modify it by writing in ckgr_pllxr, the mckrdy flag will go low while pllx is unlocked. once pllx is locked again, lockx goes high and mckrdy is set. while pllx is unlocked, the master clock selection is automatically changed to slow clock for plla and main clock for pllb. for further information, see section 30.16.2 ?clock switching waveforms? . code example: write_register(pmc_mckr,0x00000001) wait (mckrdy=1) write_register(pmc_mckr,0x00000011) wait (mckrdy=1) the master clock is main clock divided by 2.
543 sam4cp [datasheet] 43051e?atpl?08/14 8. select the programmable clocks: programmable clocks are controlled via registers, pmc_scer, pmc_scdr and pmc_scsr. programmable clocks can be enabled and/or disabled via pmc_scer and pmc_scdr. three programmable clocks can be used. pmc_scsr indicates which programmable clock is enabled. by default all programmable clocks are disabled. pmc_pckx registers are used to configure programmable clocks. the css field is used to select the programmable clock divider source. several clock options are available: main clock, slow clock, pllack, pllbck. the slow clock is the default clock source. the pres field is used to control the programmable clock prescaler. it is possible to choose between different values (1, 2, 4, 8, 16, 32, 64). programmable clock output is prescaler input divided by pres parameter. by default, the pres value is set to 0 which means that pckx is equal to slow clock. once pmc_pckx register has been configured, the corresponding programmable clock must be enabled and the user is constrained to wait for the pckrdyx bit to be set in the pmc_sr. this can be done either by polling pckrdyx in pmc_sr or by waiting for the interrupt line to be raised if the associated interrupt source (pckrdyx) has been enabled in pmc_ier. all parameters in pmc_pckx can be programmed in a single write operation. if the css and pres parameters are to be modified, the corresponding programmable clock must be disabled first. the parameters can then be modified. once this has been done, the user must re-enable the programmable clock and wait for the pckrdyx bit to be set. 9. enable the peripheral clocks: once all of the previous steps have been completed, the peripheral clocks can be enabled and/or disabled via registers pmc_pcer0, pmc_pcer, pmc_pcdr0 and pmc_pcdr. 30.16 clock switching details 30.16.1 master clock switching timings table 30-1 and give the worst case timings requ ired for the master clock to switch from one selected clock to another one. this is in the event that the prescaler is de-activated. when the prescaler is activated, an additional time of 64 clock cycles of the newly selected clock has to be added. notes: 1. pll designates either the plla or the pllb clock. 2. pllcount designates either pllacount or pllbcount. table 30-1. clock switching timings (worst case) from main clock slck pll clock to main clock ? 4 x slck + 2.5 x main clock 3 x pll clock + 4 x slck + 1 x main clock slck 0.5 x main clock + 4.5 x slck ? 3 x pll clock + 5 x slck pll clock 0.5 x main clock + 4 x slck + pllcount x slck + 2.5 x pllx clock 2.5 x pll clock + 5 x slck + pllcount x slck 2.5 x pll clock + 4 x slck + pllcount x slck
544 sam4cp [datasheet] 43051e?atpl?08/14 30.16.2 clock switching waveforms figure 30-5. switch master clock from slow clock to pllx clock table 30-2. clock switching timings between two plls (worst case) from plla clock pllb clock to plla clock 2.5 x plla clock + 4 x slck + pllacount x slck 3 x plla clock + 4 x slck + 1.5 x plla clock pllb clock 3 x pllb clock + 4 x slck + 1.5 x pllb clock 2.5 x pllb clock + 4 x slck+ pllbcount x slck slow clock lock mckrdy master clock w rite pmc_mckr pllx clock
545 sam4cp [datasheet] 43051e?atpl?08/14 figure 30-6. switch master clock from main clock to slow clock figure 30-7. change pllx programming slow clock main clock mckrdy master clock w rite pmc_mckr slow clock slow clock pllx clock lockx mckrdy master clock w rite ckgr_pllxr
546 sam4cp [datasheet] 43051e?atpl?08/14 figure 30-8. programmable clock output programming 30.17 register write protection to prevent any single software error from corrupting pmc behavior, certain registers in the address space can be write protected by setting the wpen bit in the ?pmc write protection mode register? (pmc_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the ?pmc write protection status register? (pmc_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the pmc_wpsr. the following registers can be write-protected: ? ?pmc system clock enable register? ? ?pmc system clock disable register? ? ?pmc peripheral clock enable register 0? ? ?pmc peripheral clock disable register 0? ? ?pmc clock generator main oscillator register? ? ?pmc clock generator plla register? ? ?pmc clock generator pllb register? ? ?pmc master clock register? ? ?pmc programmable clock register? ? ?pmc fast startup mode register? ? ?pmc fast startup polarity register? ? ?pmc coprocessor fast startup mode register? ? ?pmc peripheral clock enable register 1? ? ?pmc peripheral clock disable register 1? ? ?pmc oscillator calibration register? pllx clock pckrdy pckx output write pmc_pckx w rite pmc_scer w rite pmc_scdr pckx is disabled pckx is enabled pll clock is selected
547 sam4cp [datasheet] 43051e?atpl?08/14 30.18 power management controller (pmc) user interface note: if an offset is not listed in the table it must be considered as ?reserved?. table 30-3. register mapping offset register name access reset 0x0000 system clock enable register pmc_scer write-only ? 0x0004 system clock disable register pmc_scdr write-only ? 0x0008 system clock status register pmc_scsr read-only 0x0000_0001 0x000c reserved ? ? ? 0x0010 peripheral clock enable register 0 pmc_pcer0 write-only ? 0x0014 peripheral clock disable register 0 pmc_pcdr0 write-only ? 0x0018 peripheral clock status register 0 pmc_pcsr0 read-only 0x0000_0000 0x0020 main oscillator register ckgr_mor read/write 0x0000_0008 0x0024 main clock frequency register ckgr_mcfr read/write 0x0000_0000 0x0028 plla register ckgr_pllar read/write 0x0000_3f00 0x002c pllb register ckgr_pllbr read/write 0x0000_3f00 0x0030 master clock register pmc_mckr read/write 0x0000_0001 0x0034 - 0x003c reserved ? ? ? 0x0040 programmable clock 0 register pmc_pck0 read/write 0x0000_0000 0x0044 programmable clock 1 register pmc_pck1 read/write 0x0000_0000 0x0048 programmable clock 2 register pmc_pck2 read/write 0x0000_0000 0x004c - 0x005c reserved ? ? ? 0x0060 interrupt enable register pmc_ier write-only ? 0x0064 interrupt disable register pmc_idr write-only ? 0x0068 status register pmc_sr read-only 0x0001_0008 0x006c interrupt mask register pmc_imr read-only 0x0000_0000 0x0070 fast startup mode register pmc_fsmr read/write 0x0000_0000 0x0074 fast startup polarity register pmc_fspr read/write 0x0000_0000 0x0078 fault output clear register pmc_focr write-only ? 0x007c coprocessor fast startup mode register pmc_cpfsmr read/write 0x0000_0000 0x0080 - 0x00e0 reserved ? ? ? 0x00e4 write protection mode register pmc_wpmr read/write 0x0 0x00e8 write protection status register pmc_wpsr read-only 0x0 0x00ec - 0x00fc reserved ? ? ? 0x0100 peripheral clock enable register 1 pmc_pcer1 write-only ? 0x0104 peripheral clock disable register 1 pmc_pcdr1 write-only ? 0x0108 peripheral clock status register 1 pmc_pcsr1 read-only 0x0000_0000 0x010c reserved ? ? ? 0x0110 oscillator calibration register pmc_ocr read/write 0x0040_4040 0x114 - 0x120 reserved ? ? ? 0x134 - 0x144 reserved ? ? ?
548 sam4cp [datasheet] 43051e?atpl?08/14 30.18.1 pmc system clock enable register name: pmc_scer address: 0x400e0400 access: write-only this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? pckx: programmable clock x output enable 0 = no effect. 1 = enables the corresponding programmable clock output. ? cpck: coprocessor (second processor) clocks enable 0 = no effect. 1 = enables the corresponding coprocessor clocks (cphclk, cpsystick) if cpkey = 0xa. ? cpbmck: coprocessor bus master clocks enable 0 = no effect. 1 = enables the corresponding coprocessor bus master clock (cpbmck,cpfclk) if cpkey = 0xa. note: enabling cpbmck must be performed prior or at the same time as cpck is programmed to 1 in pmc_scer register or prior communication with one the peripherals of the coprocessor system bus. ? cpkey: coprocessor clocks enable key 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 cpkey ? ? cpbmck cpck 15 14 13 12 11 10 9 8 ? ? ? ? ? pck2 pck1 pck0 76543210 ???????? value name description 0xa passwd this field must be written to 0xa in order to validate cpck field.
549 sam4cp [datasheet] 43051e?atpl?08/14 30.18.2 pmc system clock disable register name: pmc_scdr address: 0x400e0404 access: write-only this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? pckx: programmable clock x output disable 0 = no effect. 1 = disables the corresponding programmable clock output. ? cpck: coprocessor clocks disable 0 = no effect. 1 = enables the corresponding coprocessor clocks (cphclk,cpfclk,cpsystick) if cpkey = 0xa. ? cpbmck: coprocessor bus master clocks disable 0 = no effect. 1 = disables the corresponding coprocessor bus master clock (cpbmck,cpfclk) if cpkey = 0xa. note: disabling cpbmck must not be performed if cpck is 1 in pmc_scsr register. ? cpkey: coprocessor clocks disable key 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 cpkey ? ? cpbmck cpck 15 14 13 12 11 10 9 8 ? ? ? ? ? pck2 pck1 pck0 76543210 ???????? value name description 0xa passwd this field must be written to 0xa in order to validate cpck field.
550 sam4cp [datasheet] 43051e?atpl?08/14 30.18.3 pmc system clock status register name: pmc_scsr address: 0x400e0408 access: read-only ? pckx: programmable clock x output status 0 = the corresponding programmable clock output is disabled. 1 = the corresponding programmable clock output is enabled. ? cpck: coprocessor (second processor) clocks status 0 = coprocessor clocks (cphclk,cpsystick) are disabled (value after reset). 1 = coprocessor clocks (cphclk,cpsystick) are enabled. ? cpbmck: coprocessor bus master clock status 0 = coprocessor clocks (cpbmck,cpfclk) are disabled (value after reset). 1 = coprocessor clocks (cpbmck,cpfclk) are enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ? ? cpbmck cpck 15 14 13 12 11 10 9 8 ? ? ? ? ? pck2 pck1 pck0 76543210 ????????
551 sam4cp [datasheet] 43051e?atpl?08/14 30.18.4 pmc peripheral clock enable register 0 name: pmc_pcer0 address: 0x400e0410 access: write-only this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? pidx: peripheral clock x enable 0 = no effect. 1 = enables the corresponding peripheral clock. note: pidx refers to identifiers defined in the section ?peripheral identifiers?. other peripherals can be enabled in pmc_pcer1 ( section 30.18.23 ?pmc peripheral clock enable register 1? ). note: programming the control bits of the peripheral id that are not implemented has no effect on the behavior of the pmc. 31 30 29 28 27 26 25 24 pid31 pid30 pid29 pid28 pid27 pid26 pid25 pid24 23 22 21 20 19 18 17 16 pid23 ? pid21 pid20 pid19 pid18 pid17 pid16 15 14 13 12 11 10 9 8 pid15 pid14 pid13 pid12 pid11 pid10 pid9 pid8 76543210 ????????
552 sam4cp [datasheet] 43051e?atpl?08/14 30.18.5 pmc peripheral clock disable register 0 name: pmc_pcdr0 address: 0x400e0414 access: write-only this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? pidx: peripheral clock x disable 0 = no effect. 1 = disables the corresponding peripheral clock. note: pidx refers to identifiers defined in the section ?peripheral identifiers?. other peripherals can be disabled in pmc_pcdr1 ( section 30.18.24 ?pmc peripheral clock disable register 1? ). 31 30 29 28 27 26 25 24 pid31 pid30 pid29 pid28 pid27 pid26 pid25 pid24 23 22 21 20 19 18 17 16 pid23 ? pid21 pid20 pid19 pid18 pid17 pid16 15 14 13 12 11 10 9 8 pid15 pid14 pid13 pid12 pid11 pid10 pid9 pid8 76543210 ????????
553 sam4cp [datasheet] 43051e?atpl?08/14 30.18.6 pmc peripheral clock status register 0 name: pmc_pcsr0 address: 0x400e0418 access: read-only ? pidx: peripheral clock x status 0 = the corresponding peripheral clock is disabled. 1 = the corresponding peripheral clock is enabled. note: pidx refers to identifiers defined in the section ?peripheral identifiers?. other peripherals status can be read in pmc_pcsr1 ( section 30.18.25 ?pmc peripheral clock status register 1? ). 31 30 29 28 27 26 25 24 pid31 pid30 pid29 pid28 pid27 pid26 pid25 pid24 23 22 21 20 19 18 17 16 pid23 ? pid21 pid20 pid19 pid18 pid17 pid16 15 14 13 12 11 10 9 8 pid15 pid14 pid13 pid12 pid11 pid10 pid9 pid8 76543210 ????????
554 sam4cp [datasheet] 43051e?atpl?08/14 30.18.7 pmc clock generator main oscillator register name: ckgr_mor address: 0x400e0420 access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? moscxten: main crystal oscillator enable a crystal must be connected between xin and xout. 0 = the main crystal oscillator is disabled. 1 = the main crystal oscillator is enabled. moscxtby must be set to 0. when moscxten is set, the moscxts flag is set once the main crystal oscillator start-up time is achieved. ? moscxtby: main crystal oscillator bypass 0 = no effect. 1 = the main crystal oscillator is bypassed. moscxten must be set to 0. an external clock must be connected on xin. when moscxtby is set, the moscxts flag in pmc_sr is automatically set. clearing moscxten and moscxtby bits resets the moscxts flag. note: when the main crystal oscillator bypass is disabled (moscxtby=0), the moscxts flag must be read at 0 in pmc_sr before enabling the main crystal oscillator (moscxten=1). ? waitmode: wait mode command 0 = no effect. 1 = puts the device in wait mode. note: the waitmode bit is write-only. ? moscrcen: main on-chip rc oscillator enable 0 = the main on-chip rc oscillator is disabled. 1 = the main on-chip rc oscillator is enabled. when moscrcen is set, the moscrcs flag is set once the main on-chip rc oscillator start-up time is achieved. 31 30 29 28 27 26 25 24 ? ? ? ? ? xt32kfme cfden moscsel 23 22 21 20 19 18 17 16 key 15 14 13 12 11 10 9 8 moscxtst 76543210 ? moscrcf moscrcen waitmode moscxtby moscxten
555 sam4cp [datasheet] 43051e?atpl?08/14 ? moscrcf: main on-chip rc oscillator frequency selection at start-up, the main on-chip rc oscillator frequency is 4 mhz. note: moscrcf must be changed only if moscrcs is set in the pmc_sr register. therefore moscrcf and moscrcen cannot be changed at the same time. ? moscxtst: main crystal oscillator start-up time specifies the number of slow clock cycles multiplied by 8 for the main crystal oscillator start-up time. ? key: write access password ? moscsel: main oscillator selection 0 = the main on-chip rc oscillator is selected. 1 = the main crystal oscillator is selected. ? cfden: clock failure detector enable 0 = the clock failure detector is disabled. 1 = the clock failure detector is enabled. note: 1. the slow rc oscillator must be enabled when the cfden is enabled. ? xt32kfme: slow crystal oscillator frequency monitoring enable 0 = the 32768 hz crystal oscillator frequency monitoring is disabled. 1 = the 32768 hz crystal oscillator frequency monitoring is enabled. value name description 0x0 4_mhz the fast rc oscillator frequency is at 4 mhz (default) 0x1 8_mhz the fast rc oscillator frequency is at 8 mhz 0x2 12_mhz the fast rc oscillator frequency is at 12 mhz value name description 0x37 passwd writing any other value in this field aborts the write operation. always reads as 0.
556 sam4cp [datasheet] 43051e?atpl?08/14 30.18.8 pmc clock generator main clock frequency register name: ckgr_mcfr address: 0x400e0424 access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? mainf: main clock frequency gives the number of main clock cycles within 16 slow clock periods in order to determine the main clock frequency: f mck = (mainf x f slck ) / 16 where frequency is in mhz. ? mainfrdy: main clock ready 0 = mainf value is not valid or the main oscillator is disabled or a measure has just been started by means of rcmeas. 1 = the main oscillator has been enabled previously and mainf value is available. note: to ensure that a correct value is read on the mainf field, the mainfrdy flag must be read at 1 then another read access must be performed on the register to get a stable value on the mainf field. ? rcmeas: rc oscillator frequency measure (write-only) 0 = no effect. 1 = restarts measuring of the main rc frequency. mainf will carry the new frequency as soon as a low to high transition occurs on the mainfrdy flag. the measure is performed on the main frequency (i.e. not limited to rc oscillator only), but if the main clock frequency source is the fast crystal oscillator, the restart of measuring is not needed because of the well known stability of crystal oscillators. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? rcmeas ? ? ? mainfrdy 15 14 13 12 11 10 9 8 mainf 76543210 mainf
557 sam4cp [datasheet] 43051e?atpl?08/14 30.18.9 pmc clock generator plla register name: ckgr_pllar address: 0x400e0428 access: read/write possible limitations on plla input frequencies and multiplier factors should be checked before using the pmc. this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? pllaen: plla control 0 = plla is disabled. 1 = plla is enabled. 2 up to 255 = forbidden. ? pllacount: plla counter specifies the number of slow clock cycles before the locka bit is set in pmc_sr after ckgr_pllar is written. ? mula: plla multiplier 0 = the plla is deactivated (plla also disabled if diva = 0). 200 up to 250 = the plla clock frequency is the plla input frequency multiplied by mula + 1. to change the plla frequency, please read section 29.6.1 ?divider and phase lock loop programming? on page 534 . 31 30 29 28 27 26 25 24 ? ? ? ? ? mula 23 22 21 20 19 18 17 16 mula 15 14 13 12 11 10 9 8 ? ? pllacount 76543210 pllaen
558 sam4cp [datasheet] 43051e?atpl?08/14 30.18.10 pmc clock generator pllb register name: ckgr_pllbr address: 0x400e042c access: read/write possible limitations on pllb input frequencies and multiplier factors should be checked before using the pmc. this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? divb: pllb front-end divider 0 = divider output is stuck at 0 and pllb is disabled. 1= divider is bypassed (divide by 1). 2 up to 255 = clock is divided by divb. ? pllbcount: pllb counter specifies the number of slow clock cycles before the lockb bit is set in pmc_sr after ckgr_pllbr is written. ? mulb: pllb multiplier 0 = the pllb is deactivated (pllb also disabled if divb = 0). 1 up to 62 = the pllb clock frequency is the pllb input frequency multiplied by mulb + 1. ? srcb: source for pllb 31 30 29 28 27 26 25 24 ? ? srcb ? ? mulb 23 22 21 20 19 18 17 16 mulb 15 14 13 12 11 10 9 8 ? ? pllbcount 76543210 divb value name description 0 mainck_in_pllb the pllb input clock is main clock. 1 plla_in_pllb the pllb input clock is plla output.
559 sam4cp [datasheet] 43051e?atpl?08/14 30.18.11 pmc master clock register name: pmc_mckr address: 0x400e0430 access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? css: master clock source selection ? pres: processor clock prescaler ? plladiv2: plla divisor by 2 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 cppres ? cpcss 15 14 13 12 11 10 9 8 ? ? pllbdiv2 plladiv2 ???? 76543210 ? pres ? ? css value name description 0 slow_clk slow clock is selected 1 main_clk main clock is selected 2 plla_clk plla clock is selected 3 pllb_clk pllb clock is selected value name description 0 clk_1 selected clock 1 clk_2 selected clock divided by 2 2 clk_4 selected clock divided by 4 3 clk_8 selected clock divided by 8 4 clk_16 selected clock divided by 16 5 clk_32 selected clock divided by 32 6 clk_64 selected clock divided by 64 7 clk_3 selected clock divided by 3 plladiv2 plla clock division 0 plla clock frequency is divided by 1 1 plla clock frequency is divided by 2
560 sam4cp [datasheet] 43051e?atpl?08/14 ? pllbdiv2 pllb divisor by 2 ? cpcss: coprocessor master clock source selection ? cppres: coprocessor programmable clock prescaler 0 up to 15 = the selected clock is divided by cppres+1. pllbdiv2 pllb clock division 0 pllb clock frequency is divided by 1 1 pllb clock frequency is divided by 2 value name description 0 slow_clk slow clock is selected 1 main_clk main clock is selected 2 plla_clk plla clock is selected 3 pllb_clk pllb clock is selected 4 mck master clock is selected
561 sam4cp [datasheet] 43051e?atpl?08/14 30.18.12 pmc programmable clock register name: pmc_pckx address: 0x400e0440 access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? css: master clock source selection ? pres: programmable clock prescaler 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? pres ? css value name description 0 slow_clk slow clock is selected 1 main_clk main clock is selected 2 plla_clk plla clock is selected 3 pllb_clk pllb clock is selected 4 mck master clock is selected value name description 0 clk_1 selected clock 1 clk_2 selected clock divided by 2 2 clk_4 selected clock divided by 4 3 clk_8 selected clock divided by 8 4 clk_16 selected clock divided by 16 5 clk_32 selected clock divided by 32 6 clk_64 selected clock divided by 64
562 sam4cp [datasheet] 43051e?atpl?08/14 30.18.13 pmc interrupt enable register name: pmc_ier address: 0x400e0460 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? moscxts: main crystal oscillator status interrupt enable ? locka: plla lock interrupt enable ? lockb: pllb lock interrupt enable ? mckrdy: master clock ready interrupt enable ? pckrdyx: programmable clock ready x interrupt enable ? moscsels: main oscillator selection status interrupt enable ? moscrcs: main on-chip rc status interrupt enable ? cfdev: clock failure detector event interrupt enable ? xt32kerr: slow crystal oscillator error interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr ? ? cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ? ? ? ? ? pckrdy2 pckrdy1 pckrdy0 76543210 ? ? ? ? mckrdy lockb locka moscxts
563 sam4cp [datasheet] 43051e?atpl?08/14 30.18.14 pmc interrupt disable register name: pmc_idr address: 0x400e0464 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? moscxts: main crystal oscillator status interrupt disable ? locka: plla lock interrupt disable ? lockb: pllb lock interrupt disable ? mckrdy: master clock ready interrupt disable ? pckrdyx: programmable clock ready x interrupt disable ? moscsels: main oscillator selection status interrupt disable ? moscrcs: main on-chip rc status interrupt disable ? cfdev: clock failure detector event interrupt disable ? xt32kerr: slow crystal oscillator error interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr ? ? cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ? ? ? ? ? pckrdy2 pckrdy1 pckrdy0 76543210 ? ? ? ? mckrdy lockb locka moscxts
564 sam4cp [datasheet] 43051e?atpl?08/14 30.18.15 pmc status register name: pmc_sr address: 0x400e0468 access: read-only ? moscxts: main crystal oscillator status 0 = main crystal oscillator is not stabilized. 1 = main crystal oscillator is stabilized. ? locka: plla lock status 0 = plla is not locked. 1 = plla is locked. ? lockb: pllb lock status 0 = pllb is not locked. 1 = pllb is locked. ? mckrdy: master clock status 0 = master clock is not ready. 1 = master clock is ready. ? oscsels: slow clock oscillator selection 0 = internal slow clock rc oscillator is selected. 1 = external slow clock 32 khz oscillator is selected. ? pckrdyx: programmable clock ready status 0 = programmable clock x is not ready. 1 = programmable clock x is ready. ? moscsels: main oscillator selection status 0 = selection is in progress. 1 = selection is done. ? moscrcs: main on-chip rc oscillator status 0 = main on-chip rc oscillator is not stabilized. 1 = main on-chip rc oscillator is stabilized. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr fos cfds cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ? ? ? ? ? pckrdy2 pckrdy1 pckrdy0 76543210 oscsels ? ? ? mckrdy lockb locka moscxts
565 sam4cp [datasheet] 43051e?atpl?08/14 ? cfdev: clock failure detector event 0 = no clock failure detection of the fast crystal oscillator clock has occurred since the last read of pmc_sr. 1 = at least one clock failure detection of the fast crystal oscillator clock has occurred since the last read of pmc_sr. ? cfds: clock failure detector status 0 = a clock failure of the fast crystal oscillator clock is not detected. 1 = a clock failure of the fast crystal oscillator clock is detected. ? fos: clock failure detector fault output status 0 = the fault output of the clock failure detector is inactive. 1 = the fault output of the clock failure detector is active. ? xt32kerr: slow crystal oscillator error 0 = the frequency of the slow crystal oscillator is correct (32768 hz +/- 1%) or the monitoring is disabled. 1 = the frequency of the slow crystal oscillator is incorrect or has been incorrect for an elapsed period of time since the mon itoring has been enabled.
566 sam4cp [datasheet] 43051e?atpl?08/14 30.18.16 pmc interrupt mask register name: pmc_imr address: 0x400e046c access: read-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? moscxts: main crystal oscillator status interrupt mask ? locka: plla lock interrupt mask ? lockb: pllb lock interrupt mask ? mckrdy: master clock ready interrupt mask ? pckrdyx: programmable clock ready x interrupt mask ? moscsels: main oscillator selection status interrupt mask ? moscrcs: main on-chip rc status interrupt mask ? cfdev: clock failure detector event interrupt mask ? xt32kerr: slow crystal oscillator error interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? xt32kerr ? ? cfdev moscrcs moscsels 15 14 13 12 11 10 9 8 ? ? ? ? ? pckrdy2 pckrdy1 pckrdy0 76543210 ? ? ? ? mckrdy lockb locka moscxts
567 sam4cp [datasheet] 43051e?atpl?08/14 30.18.17 pmc fast startup mode register name: pmc_fsmr address: 0x400e0470 access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? fstt0 - fstt15: fast startup input enable 0 to 15 0 = the corresponding wake-up input has no effect on the power management controller. 1 = the corresponding wake-up input enables a fast restart signal to the power management controller. ? rttal: rtt alarm enable 0 = the rtt alarm has no effect on the power management controller. 1 = the rtt alarm enables a fast restart signal to the power management controller. ? rtcal: rtc alarm enable 0 = the rtc alarm has no effect on the power management controller. 1 = the rtc alarm enables a fast restart signal to the power management controller. ? flpm: flash low-power mode 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? flpm ? ? ? rtcal rttal 15 14 13 12 11 10 9 8 fstt15 fstt14 fstt13 fstt12 fstt11 fstt10 fstt9 fstt8 76543210 fstt7 fstt6 fstt5 fstt4 fstt3 fstt2 fstt1 fstt0 value name description 0 flash_standby flash is in standby mode when system enters wait mode 1 flash_deep_powerdown flash is in deep power down mode when system enters wait mode 2 flash_idle idle mode
568 sam4cp [datasheet] 43051e?atpl?08/14 30.18.18 pmc fast startup polarity register name: pmc_fspr address: 0x400e0474 access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? fstpx: fast startup input polarityx defines the active polarity of the correspo nding wake-up input. if the corresponding wake-up input is enabled and at the fstp level, it enables a fast restart signal. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 fstp15 fstp14 fstp13 fstp12 fstp11 fstp10 fstp9 fstp8 76543210 fstp7 fstp6 fstp5 fstp4 fstp3 fstp2 fstp1 fstp0
569 sam4cp [datasheet] 43051e?atpl?08/14 30.18.19 pmc coprocessor fast startup mode register name: pmc_cpfsmr address: 0x400e047c access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? fstt0 - fstt15: fast startup input enable 0 to 15 0 = the corresponding wake-up input has no effect on the power management controller. 1 = the corresponding wake-up input enables a fast restart signal to the power management controller. ? rttal: rtt alarm enable 0 = the rtt alarm has no effect on the power management controller. 1 = the rtt alarm enables a fast restart signal to the power management controller. ? rtcal: rtc alarm enable 0 = the rtc alarm has no effect on the power management controller. 1 = the rtc alarm enables a fast restart signal to the power management controller. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ? ? rtcal rttal 15 14 13 12 11 10 9 8 fstt15 fstt14 fstt13 fstt12 fstt11 fstt10 fstt9 fstt8 76543210 fstt7 fstt6 fstt5 fstt4 fstt3 fstt2 fstt1 fstt0
570 sam4cp [datasheet] 43051e?atpl?08/14 30.18.20 pmc fault output clear register name: pmc_focr address: 0x400e0478 access: write-only ? foclr: fault output clear clears the clock failure detector fault output. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????? foclr
571 sam4cp [datasheet] 43051e?atpl?08/14 30.18.21 pmc write protection mode register name: pmc_wpmr address: 0x400e04e4 access: read/write ? wpen: write protection enable 0 = disables the write protection if wpkey corresponds to 0x504d43 (?pmc? in ascii). 1 = enables the write protection if wpkey corresponds to 0x504d43 (?pmc? in ascii). see section ?register write protection? for the list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x504d43 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
572 sam4cp [datasheet] 43051e?atpl?08/14 30.18.22 pmc write protection status register name: pmc_wpsr address: 0x400e04e8 access: read-only ? wpvs: write protection violation status 0 = no write protection violation has occurred since the last read of the pmc_wpsr. 1 = a write protection violation has occurred since the last read of the pmc_wpsr. if this violation is an unauthorized attempt to write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
573 sam4cp [datasheet] 43051e?atpl?08/14 30.18.23 pmc peripheral clock enable register 1 name: pmc_pcer1 address: 0x400e0500 access: write-only this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? pidx: peripheral clock x enable 0 = no effect. 1 = enables the corresponding peripheral clock. notes: 1. to get pidx, refer to identifiers as defined in the section ?peripheral identifiers?. 2. programming the control bits of the peripheral id that are not implemented has no effect on the behavior of the pmc. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? pid43 pid42 pid41 pid40 76543210 pid39 pid38 pid37 pid36 pid35 pid34 pid33 pid32
574 sam4cp [datasheet] 43051e?atpl?08/14 30.18.24 pmc peripheral clock disable register 1 name: pmc_pcdr1 address: 0x400e0504 access: write-only this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? pidx: peripheral clock x disable 0 = no effect. 1 = disables the corresponding peripheral clock. note: to get pidx, refer to identifiers as defined in the section ?peripheral identifiers?. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? pid43 pid42 pid41 pid40 76543210 pid39 pid38 pid37 pid36 pid35 pid34 pid33 pid32
575 sam4cp [datasheet] 43051e?atpl?08/14 30.18.25 pmc peripheral clock status register 1 name: pmc_pcsr1 address: 0x400e0508 access: read-only ? pidx: peripheral clock x status 0 = the corresponding peripheral clock is disabled. 1 = the corresponding peripheral clock is enabled. note: to get pidx, refer to identifiers as defined in the section ?peripheral identifiers?. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? pid43 pid42 pid41 pid40 76543210 pid39 pid38 pid37 pid36 pid35 pid34 pid33 pid32
576 sam4cp [datasheet] 43051e?atpl?08/14 30.18.26 pmc oscillator calibration register name: pmc_ocr address: 0x400e0510 access: read/write this register can only be written if the wpen bit is cleared in ?pmc write protection mode register? . ? cal4: rc oscillator calibration bits for 4 mhz calibration bits applied to the rc oscillator when sel4 is set. ? sel4: selection of rc oscillator calibration bits for 4 mhz 0 = default value stored in flash memory. 1 = value written by user in cal4 field of this register. ? cal8: rc oscillator calibration bits for 8 mhz calibration bits applied to the rc oscillator when sel8 is set. ? sel8: selection of rc oscillator calibration bits for 8 mhz 0 = factory determined value stored in flash memory. 1 = value written by user in cal8 field of this register. ? cal12: rc oscillator calibration bits for 12 mhz calibration bits applied to the rc oscillator when sel12 is set. ? sel12: selection of rc oscillator calibration bits for 12 mhz 0 = factory determined value stored in flash memory. 1 = value written by user in cal12 field of this register. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 sel12 cal12 15 14 13 12 11 10 9 8 sel8 cal8 76543210 sel4 cal4
577 sam4cp [datasheet] 43051e?atpl?08/14 31. chip identifier (chipid) 31.1 description chip identifier (chipid) registers permit recognition of the device and its revision. these registers provide the sizes and types of the on-chip memories, as well as the set of embedded peripherals. two chip identifier registers are embedded: chipid_cidr (chip id register) and chipid_exid (extension id). both registers contain a hard-wired value that is read-only. the first register contains the following fields: ? ext: shows the use of the extension identifier register. ? nvptyp and nvpsiz: identifies the type of embedded non-volatile memory and the size. ? arch: identifies the set of embedded peripherals. ? sramsiz: indicates the size of the embedded sram. ? eproc: indicates the embedded arm processor. ? version: gives the revision of the silicon. the second register is device-dependent and reads 0 if the bit ext is 0. 31.2 embedded characteristics ? chip id registers ? identification of the device revision, sizes of the embedded memories, set of peripherals, embedded processor. 31.3 chip identifier (chipid) user interface table 31-1. sam4cp chip ids registers chip name chipid_cidr chipid_exid sam4cp16b 0xa64c_0ce0 0x3 table 31-2. register mapping offset register name access reset 0x0 chip id register chipid_cidr read-only ? 0x4 chip id extension register chipid_exid read-only ?
578 sam4cp [datasheet] 43051e?atpl?08/14 31.3.1 chip id register name: chipid_cidr address: 0x400e0740 access: read-only ? version: version of the device current version of the device. ? eproc: embedded processor ? nvpsiz: nonvolatile program memory size 31 30 29 28 27 26 25 24 ext nvptyp arch 23 22 21 20 19 18 17 16 arch sramsiz 15 14 13 12 11 10 9 8 nvpsiz2 nvpsiz 76543210 eproc version value name description 1 arm946es arm946es 2 arm7tdmi arm7tdmi 3 cm3 cortex-m3 4 arm920t arm920t 5 arm926ejs arm926ejs 6 ca5 cortex-a5 7 cm4 cortex-m4 value name description 0 none none 1 8k 8 kbytes 2 16k 16 kbytes 3 32k 32 kbytes 4 ? reserved 5 64k 64 kbytes 6 ? reserved 7 128k 128 kbytes 8 160k 160 kbytes 9 256k 256 kbytes 10 512k 512 kbytes 11 ? reserved 12 1024k 1024 kbytes 13 ? reserved 14 2048k 2048 kbytes 15 ? reserved
579 sam4cp [datasheet] 43051e?atpl?08/14 ? nvpsiz2: second nonvolatile program memory size ? sramsiz: internal sram size ? arch: architecture identifier value name description 0 none none 1 8k 8 kbytes 2 16k 16 kbytes 3 32k 32 kbytes 4 ? reserved 5 64k 64 kbytes 6 ? reserved 7 128k 128 kbytes 8 ? reserved 9 256k 256 kbytes 10 512k 512 kbytes 11 ? reserved 12 1024k 1024 kbytes 13 ? reserved 14 2048k 2048 kbytes 15 ? reserved value name description 0 48k 48 kbytes 1 192k 192 kbytes 2 384k 384 kbytes 3 6k 6 kbytes 4 24k 24 kbytes 5 4k 4 kbytes 6 80k 80 kbytes 7 160k 160 kbytes 8 8k 8 kbytes 9 16k 16 kbytes 10 32k 32 kbytes 11 64k 64 kbytes 12 128k 128 kbytes 13 256k 256 kbytes 14 96k 96 kbytes 15 512k 512 kbytes value device 0x64 sam4cp16b
580 sam4cp [datasheet] 43051e?atpl?08/14 ? nvptyp: nonvolatile program memory type ? ext: extension flag 0 = chip id has a single register definition without extension. 1 = an extended chip id exists. value name description 0 rom rom 1 romless romless or on-chip flash 2 flash embedded flash memory 3 rom_flash rom and embedded flash memory ? nvpsiz is rom size ? nvpsiz2 is flash size 4 sram sram emulating rom
581 sam4cp [datasheet] 43051e?atpl?08/14 31.3.2 chip id extension register name: chipid_exid address: 0x400e0744 access: read-only ? exid: chip id extension this bit is cleared if the ext bit in chipid_cidr is 0. 31 30 29 28 27 26 25 24 exid 23 22 21 20 19 18 17 16 exid 15 14 13 12 11 10 9 8 exid 76543210 exid value name description 0x3 sam4cp sam4c embedding pplc peripheral
582 sam4cp [datasheet] 43051e?atpl?08/14 32. parallel input/output controller (pio) 32.1 description the parallel input/output controller (pio) manages up to 32 fully programmable input/output lines. each i/o line may be dedicated as a general-purpose i/o or be assigned to a function of an embedded peripheral. this assures effective optimization of the pins of the product. each i/o line is associated with a bit number in all of the 32-bit registers of the 32-bit wide user interface. each i/o line of the pio controller features: ? an input change interrupt enabling level change detection on any i/o line. ? additional interrupt modes enabling rising edge, falling edge, low-level or high-level detection on any i/o line. ? a glitch filter providing rejection of glitches lower than one-half of peripheral clock cycle. ? a debouncing filter providing rejection of unwanted pulses from key or push button operations. ? multi-drive capability similar to an open drain i/o line. ? control of the pull-up and pull-down of the i/o line. ? input visibility and output control. the pio controller also features a synchronous output providing up to 32 bits of data output in a single write operation. 32.2 embedded characteristics ? up to 32 programmable i/o lines. ? fully programmable through set/clear registers. ? multiplexing of four peripheral functions per i/o line. ? for each i/o line (whether assigned to a peripheral or used as general purpose i/o). ? input change interrupt. ? programmable glitch filter. ? programmable debouncing filter. ? multi-drive option enables driving in open drain. ? programmable pull-up on each i/o line. ? pin data status register, supplies visibility of the level on the pin at any time. ? additional interrupt modes on a programmable event: rising edge, falling edge, low-level or high-level. ? synchronous output, provides set and clear of several i/o lines in a single write. ? register write protection. ? programmable schmitt trigger inputs. ? programmable i/o drive.
583 sam4cp [datasheet] 43051e?atpl?08/14 32.3 block diagram figure 32-1. block diagram embedded peripheral embedded peripheral pio interrupt pio controller up to 32 pins pmc up to 32 peripheral ios up to 32 peripheral ios peripheral clock apb interrupt controller data, enable pin 31 pin 1 pin 0 data, enable
584 sam4cp [datasheet] 43051e?atpl?08/14 32.4 product dependencies 32.4.1 pin multiplexing each pin is configurable, depending on the product, as either a general-purpose i/o line only, or as an i/o line multiplexed with one or two peripheral i/os. as the multiplexing is hardware defined and thus product-dependent, the hardware designer and programmer must carefully determine the c onfiguration of the pio controllers required by their application. when an i/o line is general-purpose only, i.e. not multiplexed with any peripheral i/o, programming of the pio controller regarding the assignment to a peripheral has no effect and only the pio controller can control how the pin is driven by the product. 32.4.2 power management the power management controller controls the peripheral cloc k in order to save power. wr iting any of the registers of the user interface does not require the peripheral clock to be enabled. this means that the configuration of the i/o lines does not require the peripheral clock to be enabled. however, when the clock is disabled, not all of the features of the pio controller are available, including glitch filtering. note that the input change interrupt, the interrupt modes on a programmable event and the read of the pin level require the clock to be validated. after a hardware reset, the peripheral clock is disabled by default. the user must configure the power management controller before any access to the input line information. 32.4.3 interrupt generation for interrupt handling, the pio controllers are considered as user peripherals. this means that the pio controller interrupt lines are connected among the interrupt sources. refer to the pio controller peripheral identifier in the peripheral identifiers table to identify the interrupt sources dedicated to the pio controllers. using the pio controller requires the interrupt controller to be programmed first. the pio controller interrupt can be generated only if the peripheral clock is enabled.
585 sam4cp [datasheet] 43051e?atpl?08/14 32.5 functional description the pio controller features up to 32 fully-programmable i/o lines. most of the control logic associated to each i/o is represented in figure 32-2 . in this description each signal shown represents one of up to 32 possible indexes. figure 32-2. i/o line control logic 32.5.1 pull-up and pull-down resistor control each i/o line is designed with an embedded pull-up resistor and an embedded pull-down resistor. the pull-up resistor can be enabled or disabled by writing to the pull-up enable register (pio_puer) or pull-up disable register (pio_pudr), respectively. writing to these registers results in setting or clearing the corresponding bit in the pull-up status register (pio_pusr). reading a one in pio_pusr means the pull-up is disabled and reading a zero means the pull-up is enabled. the pull-down resistor can be enabled or disabled by writing the pull-down enable register (pio_ppder) or the pull-down disable register (pio_ppddr), respectively. writing in these registers results in setting or clearing the corresponding bit in the pull-down status register (pio_ppdsr). reading a one in pio_ppdsr means the pull-up is disabled and reading a zero means the pull-down is enabled. enabling the pull-down resistor while the pull-up resistor is still enabled is not possible. in this case, the write of pio_ppder for the relevant i/o line is discarded. likewise, en abling the pull-up resistor while the pull-down resistor is still enabled is not possible. in this case, the write of pio_puer for the relevant i/o line is discarded. control of the pull-up resistor is possible regardless of the configuration of the i/o line. after reset, depending on the i/o, pull-up or pull-down can be set. 1 0 1 0 1 0 1 0 dq dq dff 1 0 1 0 11 00 01 10 programmable glitch or debouncing filter pio_pdsr[0] pio_isr[0] pio_idr[0] pio_imr[0] pio_ier[0] pio interrupt (up to 32 possible inputs) pio_isr[31] pio_idr[31] pio_imr[31] pio_ier[31] pad pio_pudr[0] pio_pusr[0] pio_puer[0] pio_mddr[0] pio_mdsr[0] pio_mder[0] pio_codr[0] pio_odsr[0] pio_sodr[0] pio_pdr[0] pio_psr[0] pio_per[0] pio_abcdsr1[0] pio_odr[0] pio_osr[0] pio_oer[0] peripheral clock resynchronization stage peripheral a input peripheral d output enable peripheral a output enable event detector dff pio_ifdr[0] pio_ifsr[0] pio_ifer[0] peripheral clock clock divider pio_ifscsr[0] pio_ifscer[0] pio_ifscdr[0] pio_scdr slow clock peripheral b output enable peripheral c output enable 11 00 01 10 peripheral d output peripheral a output peripheral b output peripheral c output pio_abcdsr2[0] peripheral b input peripheral c input peripheral d input pio_ppddr[0] pio_ppdsr[0] pio_ppder[0] vdd gnd integrated pull-down resistor integrated pull-up resistor div_slck
586 sam4cp [datasheet] 43051e?atpl?08/14 32.5.2 i/o line or peripheral function selection when a pin is multiplexed with one or two peripheral functions, the selection is controlled with the enable register (pio_per) and the disable register (pio_pdr). the status register (pio_psr) is the result of the set and clear registers and indicates whether the pin is controlled by the corresponding peripheral or by the pio controller. a value of zero indicates that the pin is controlled by the corresponding on-chip peripheral selected in the abcd select registers (pio_abcdsr1 and pio_abcdsr2). a value of one indicates the pin is controlled by the pio controller. if a pin is used as a general-purpose i/o line (not multiplexed with an on-chip peripheral), pio_per and pio_pdr have no effect and pio_psr returns a one for the corresponding bit. after reset, the i/o lines are controlled by the pio controller, i.e. pio_psr resets at one. however, in some events, it is important that pio lines are controlled by the peripheral (as in the case of memory chip select lines that must be driven inactive after reset, or for address lines that must be driven low for booting out of an external memory). thus, the reset value of pio_psr is defined at the product level and depends on the multiplexing of the device. 32.5.3 peripheral a or b or c or d selection the pio controller provides multiplexing of up to four peripheral functions on a single pin. the selection is performed by writing pio_abcdsr1 and pio_abcdsr2. for each pin: ? the corresponding bit at level zero in pio_abcdsr1 and the corresponding bit at level zero in pio_abcdsr2 means peripheral a is selected. ? the corresponding bit at level one in pio_abcdsr1 and the corresponding bit at level zero in pio_abcdsr2 means peripheral b is selected. ? the corresponding bit at level zero in pio_abcdsr1 and the corresponding bit at level one in pio_abcdsr2 means peripheral c is selected. ? the corresponding bit at level one in pio_abcdsr1 and the corresponding bit at level one in pio_abcdsr2 means peripheral d is selected. note that multiplexing of peripheral lines a, b, c and d only affects the output line. the peripheral input lines are always connected to the pin input (see figure 32-2 ). writing in pio_abcdsr1 and pio_abcdsr2 manages the multiplexing regardless of the configuration of the pin. however, assignment of a pin to a peripheral function requires a write in pio_abcdsr1 and pio_abcdsr2 in addition to a write in pio_pdr. after reset, pio_abcdsr1 and pio_abcdsr2 are zero, thus indicating that all the pio lines are configured on peripheral a. however, peripheral a generally does not drive the pin as the pio controller resets in i/o line mode. if the software selects a peripheral a, b, c or d which does not exist for a pin, no alternate functions are enabled for this pin and the selection is taken into account. the pio controller does not carry out checks to prevent selection of a peripheral which does not exist. 32.5.4 output control when the i/0 line is assigned to a peripheral function, i.e. the corresponding bit in pio_psr is at zero, the drive of the i/o line is controlled by the peripheral. peripheral a or b or c or d depending on the value in pio_abcdsr1 and pio_abcdsr2 determines whether the pin is driven or not. when the i/o line is controlled by the pio controller, the pin can be configured to be driven. this is done by writing the output enable register (pio_oer) and output disable register (pio_odr). the results of these write operations are detected in the output status register (pio_osr). when a bit in this register is at zero, the corresponding i/o line is used as an input only. when the bit is at one, the corresponding i/o line is driven by the pio controller. the level driven on an i/o line can be determined by writing in the set output data register (pio_sodr) and the clear output data register (pio_codr). these write operations, respectively, set and cl ear the output data status register (pio_odsr), which represents the data driven on the i/o lines. writing in pio_oer and pio_odr manages pio_osr
587 sam4cp [datasheet] 43051e?atpl?08/14 whether the pin is configured to be controlled by the pio controller or assigned to a peripheral function. this enables configuration of the i/o line prior to setting it to be managed by the pio controller. similarly, writing in pio_sodr and pio_codr affects pio_ odsr. this is important as it defines the first level driven on the i/o line. 32.5.5 synchronous data output clearing one or more pio line(s) and setting another one or more pio line(s) synchronously cannot be done by using pio_sodr and pio_codr registers. it requires two successive write operations into two different registers. to overcome this, the pio controller offers a direct control of pio outputs by single write access to pio_odsr. only bits unmasked by the output write status register (pio_owsr) are written. the mask bits in pio_owsr are set by writing to the output write enable register (pio_ower) and cleared by writing to the output write disable register (pio_owdr). after reset, the synchronous data output is disabled on all the i/o lines as pio_owsr resets at 0x0. 32.5.6 multi-drive control (open drain) each i/o can be independently programmed in open drain by using the multi-drive feature. this feature permits several drivers to be connected on the i/o line which is driven low only by each device. an external pull-up resistor (or enabling of the internal one) is generally required to guarantee a high level on the line. the multi-drive feature is controlled by the multi-driver enable register (pio_mder) and the multi-driver disable register (pio_mddr). the multi-drive can be selected whether the i/o li ne is controlled by the pio controller or assigned to a peripheral function. the multi-driver status register (pio_mdsr) indicates the pins that are configured to support external drivers. after reset, the multi-drive feature is disabled on all pins, i.e. pio_mdsr resets at value 0x0. 32.5.7 output line timings figure 32-3 shows how the outputs are driven either by writing pio_sodr or pio_codr, or by directly writing pio_odsr. this last case is valid only if the corresponding bit in pio_owsr is set. figure 32-3 also shows when the feedback in the pin data status register (pio_pdsr) is available. figure 32-3. output line timings 32.5.8 inputs the level on each i/o line can be read through pio_pdsr. this register indicates the level of the i/o lines regardless of their configuration, whether uniquely as an input, or driven by the pio controller, or driven by a peripheral. reading the i/o line levels requires the clock of the pio controller to be enabled, otherwise pio_pdsr reads the levels present on the i/o line at the time the clock was disabled. 2 cycles apb access 2 cycles apb access peripheral clock write pio_sodr write pio_odsr at 1 pio_odsr pio_pdsr write pio_codr write pio_odsr at 0
588 sam4cp [datasheet] 43051e?atpl?08/14 32.5.9 input glitch and debouncing filters optional input glitch and debouncing filters are independently programmable on each i/o line. the glitch filter can filter a glitch with a duration of less than 1/2 peripheral clock and the debouncing filter can filter a pulse of less than 1/2 period of a programmable divided slow clock. the selection between glitch filtering or debounce filtering is done by writing in the pio input filter slow clock disable register (pio_ifscdr) and the pio input filter slow clock enable register (pio_ifscer). writing pio_ifscdr and pio_ifscer, respectively, sets and clears bits in the input filter slow clock status register (pio_ifscsr). the current selection status can be checked by reading the register pio_ifscsr. ? if pio_ifscsr[i] = 0: the glitch filter can filter a glitch with a duration of less than 1/2 peripheral clock period. ? if pio_ifscsr[i] = 1: the debouncing filter can filter a pulse with a duration of less than 1/2 programmable divided slow clock period. for the debouncing filter, the period of the divided slow clock is defined by writing in the div field of the slow clock divider debouncing register (pio_scdr). t div_slck = ((div+1) * 2) * t slck when the glitch or debouncing filter is enabled, a glitch or pulse with a duration of less than 1/2 selected clock cycle (selected clock represents peripheral clock or divided slow clock depending on pio_ifscdr and pio_ifscer programming) is automatically rejected, while a pulse with a duration of one selected clock (peripheral clock or divided slow clock) cycle or more is accepted. for pulse durations between 1/2 selected clock cycle and one selected clock cycle, the pulse may or may not be taken into account, depending on the precise timing of its occurrence. thus for a pulse to be visible, it must exceed one selected clock cycle, whereas for a glitch to be reliably filtered out, its duration must not exceed 1/2 selected clock cycle. the filters also introduce some latencies, illustrated in figure 32-4 and figure 32-5 . the glitch filters are controlled by the input filter enable register (pio_ifer), the input filter disable register (pio_ifdr) and the input filter status register (pio_ifsr). writing pio_ifer and pio_ifdr respectively sets and clears bits in pio_ifsr. this last register enables the glitch filter on the i/o lines. when the glitch and/or debouncing filter is enabled, it does not modify the behavior of the inputs on the peripherals. it acts only on the value read in pio_pdsr and on the input change interrupt detection. the glitch and debouncing filters require that the peripheral clock is enabled. figure 32-4. input glitch filter timing peripheral clcok pin level pio_pdsr if pio_ifsr = 0 pio_pdsr if pio_ifsr = 1 1 cycle 1 cycle 1 cycle up to 1.5 cycles 2 cycles up to 2.5 cycles up to 2 cycles 1 cycle 1 cycle pio_ifcsr = 0
589 sam4cp [datasheet] 43051e?atpl?08/14 figure 32-5. input debouncing filter timing 32.5.10 input edge/level interrupt the pio controller can be programmed to ge nerate an interrupt when it detects an edge or a level on an i/o line. the input edge/level interrupt is controlled by writing the interrupt enable register (pio_ier) and the interrupt disable register (pio_idr), which enable and disable the input change interrupt respectively by setting and clearing the corresponding bit in the interrupt mask register (pio_imr). as input change detection is possible only by comparing two successive samplings of the input of the i/o line, the peripheral clock must be enabled. the input change interrupt is available regardless of the configuration of the i/o line, i.e. configured as an input only, controlled by the pio controller or assigned to a peripheral function. by default, the interrupt can be generated at any time an edge is detected on the input. some additional interrupt modes can be enabled/disabled by writing in the additional interrupt modes enable register (pio_aimer) and additional interrupt modes disable register (pio_aimdr). the current state of this selection can be read through the additional interrupt modes mask register (pio_aimmr). these additional modes are: ? rising edge detection. ? falling edge detection. ? low-level detection. ? high-level detection. in order to select an additional interrupt mode: ? the type of event detection (edge or level) must be selected by writing in the edge select register (pio_esr) and the level select register (pio_lsr) which select, respectively, the edge and level detection. the current status of this selection is accessible through the edge/level status register (pio_elsr). ? the polarity of the event detection (rising/falling edge or high/low-level) must be selected by writing in the falling edge/low-level select register (pio_fellsr) and rising edge/high level select register (pio_rehlsr) which allow to select falling or rising edge (if edge is selected in pio_elsr) edge or high- or low-level detection (if level is selected in the pio_elsr). the current status of this selection is accessible through the fall/rise - low/high status register (pio_frlhsr). when an input edge or level is detected on an i/o line, the corresponding bit in the interrupt status register (pio_isr) is set. if the corresponding bit in pio_imr is set, the pio controller interrupt line is asserted.the interrupt signals of the 32 channels are ored-wired together to generate a single interrupt signal to the interrupt controller. when the software reads pio_isr, all the interrupts are auto matically cleared. this signifie s that all the interrupts that are pending when pio_isr is read must be handled. when an interrupt is enabled on a ?level?, the interrupt is generated as long as the interrupt source is not cleared, even if some read accesses in pio_isr are performed. divided slow clock (div_slck) pin level pio_pdsr if pio_ifsr = 0 pio_pdsr if pio_ifsr = 1 1 cycle t div_slck up to 1.5 cycles t div_slck 1 cycle t div_slck up to 2 cycles t peripheral clock up to 2 cycles t peripheral clock up to 2 cycles t peripheral clock up to 2 cycles t peripheral clock up to 1.5 cycles t div_slck pio_ifcsr = 1
590 sam4cp [datasheet] 43051e?atpl?08/14 figure 32-6. event detector on input lines (figure represents line 0) example of interrupt generation on following lines: ? rising edge on pio line 0 ? falling edge on pio line 1 ? rising edge on pio line 2 ? low-level on pio line 3 ? high-level on pio line 4 ? high-level on pio line 5 ? falling edge on pio line 6 ? rising edge on pio line 7 ? any edge on the other lines table 32-1 details the required configuration for this example. table 32-1. configuration for example interrupt generation configuration description interrupt mode all the interrupt sources are enabled by writing 32?hffff_ffff in pio_ier. then the additional interrupt mode is enabled for lines 0 to 7 by writing 32?h0000_00ff in pio_aimer. edge or level detection lines 3, 4 and 5 are configured in level detection by writing 32?h0000_0038 in pio_lsr. the other lines are configured in edge detection by default, if they have not been previously configured. otherwise, lines 0, 1, 2, 6 and 7 must be configured in edge detection by writing 32?h0000_00c7 in pio_esr. falling/rising edge or low/high- level detection lines 0, 2, 4, 5 and 7 are configured in rising edge or high-level detection by writing 32?h0000_00b5 in pio_rehlsr. the other lines are configured in falling edge or low-level detection by default if they have not been previously configured. otherwise, lines 1, 3 and 6 must be configured in falling edge/low-level detection by writing 32?h0000_004a in pio_fellsr. event detector 0 1 0 1 1 0 0 1 edge detector falling edge detector rising edge detector pio_fellsr[0] pio_frlhsr[0] pio_rehlsr[0] low level detector high level detector pio_esr[0] pio_elsr[0] pio_lsr[0] pio_aimdr[0] pio_aimmr[0] pio_aimer[0] event detection on line 0 r esynchronized input on line 0
591 sam4cp [datasheet] 43051e?atpl?08/14 figure 32-7. input change interrupt timings when no additional interrupt modes 32.5.11 programmable i/o drive it is possible to configure the i/o drive for pads pa1 to pa4, pa9 to pa28, pa30, pb0, pb2 to pb12, pb14 to pb29, pb31, pc1 to pc4 and pc6 to pc9. refer to the section ?electrical characteristics?. 32.5.12 programmable schmitt trigger it is possible to configure each input for the schmitt trigger. by default the schmitt trigger is active. disabling the schmitt trigger is requested when using the qtouch ? library. 32.5.13 i/o lines programming example the programming example shown in table 32-2 is used to obtain the following configuration. ? 4-bit output port on i/o lines 0 to 3, (should be written in a single write operation), open-drain, with pull-up resistor. ? four output signals on i/o lines 4 to 7 (to drive leds for example), driven high and low, no pull-up resistor, no pull-down resistor. ? four input signals on i/o lines 8 to 11 (to read push-button states for example), with pull-up resistors, glitch filters and input change interrupts. ? four input signals on i/o line 12 to 15 to read an external device status (polled, thus no input change interrupt), no pull-up resistor, no glitch filter. ? i/o lines 16 to 19 assigned to peripheral a functions with pull-up resistor. ? i/o lines 20 to 23 assigned to peripheral b functions with pull-down resistor. ? i/o line 24 to 27 assigned to peripheral c with input change interrupt, no pull-up resistor and no pull-down resistor. ? i/o line 28 to 31 assigned to peripheral d, no pull-up resistor and no pull-down resistor. peripheral clock pin level read pio_isr apb access pio_isr apb access table 32-2. programming example register value to be written pio_per 0x0000_ffff pio_pdr 0xffff_0000 pio_oer 0x0000_00ff pio_odr 0xffff_ff00 pio_ifer 0x0000_0f00 pio_ifdr 0xffff_f0ff pio_sodr 0x0000_0000 pio_codr 0x0fff_ffff pio_ier 0x0f00_0f00 pio_idr 0xf0ff_f0ff
592 sam4cp [datasheet] 43051e?atpl?08/14 32.5.14 register write protection to prevent any single software error from corrupting pio behavior, certain registers in the address spaces can be write- protected by setting the wpen bit in the ?pio write protection mode register? (pio_wpmr). if a write access to a write-protected reg ister is detected, the wpvs flag in the ?pio write protection status register? (pio_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the pio_wpsr. the following registers can be write-protected: ? ?pio enable register? on page 596 ? ?pio disable register? on page 597 ? ?pio output enable register? on page 599 ? ?pio output disable register? on page 600 ? ?pio input filter enable register? on page 602 ? ?pio input filter disable register? on page 603 ? ?pio multi-driver enable register? on page 613 ? ?pio multi-driver disable register? on page 614 ? ?pio pull-up disable register? on page 616 ? ?pio pull-up enable register? on page 617 ? ?pio peripheral abcd select register 1? on page 619 ? ?pio peripheral abcd select register 2? on page 620 ? ?pio output write enable register? on page 628 ? ?pio output write disable register? on page 629 ? ?pio pad pull-down disable register? on page 625 ? ?pio pad pull-down status register? on page 627 pio_mder 0x0000_000f pio_mddr 0xffff_fff0 pio_pudr 0xfff0_00f0 pio_puer 0x000f_ff0f pio_ppddr 0xff0f_ffff pio_ppder 0x00f0_0000 pio_abcdsr1 0xf0f0_0000 pio_abcdsr2 0xff00_0000 pio_ower 0x0000_000f pio_owdr 0x0fff_ fff0 table 32-2. programming example
593 sam4cp [datasheet] 43051e?atpl?08/14 32.6 parallel input/output controller (pio) user interface each i/o line controlled by the pio controller is associated with a bit in each of the pio controller user interface registers. each register is 32 bits wide. if a parallel i/o line is not defined, writing to the corresponding bits has no effec t. undefined bits read zero. if the i/o line is not multiplexed with any peripheral, the i/o line is controlled by the pio controller and pio_psr returns one systematically. table 32-3. register mapping (1) offset register name access reset 0x0000 pio enable register pio_per write-only ? 0x0004 pio disable register pio_pdr write-only ? 0x0008 pio status register pio_psr read-only (2) 0x000c reserved ? ? ? 0x0010 output enable register pio_oer write-only ? 0x0014 output disable register pio_odr write-only ? 0x0018 output status register pio_osr read-only 0x0000 0000 0x001c reserved ? ? ? 0x0020 glitch input filter enable register pio_ifer write-only ? 0x0024 glitch input filter disable register pio_ifdr write-only ? 0x0028 glitch input filter status register pio_ifsr read-only 0x0000 0000 0x002c reserved ? ? ? 0x0030 set output data register pio_sodr write-only ? 0x0034 clear output data register pio_codr write-only 0x0038 output data status register pio_odsr read-only or (3) read/write ? 0x003c pin data status register pio_pdsr read-only (4) 0x0040 interrupt enable register pio_ier write-only ? 0x0044 interrupt disable register pio_idr write-only ? 0x0048 interrupt mask register pio_imr read-only 0x00000000 0x004c interrupt status register (5) pio_isr read-only 0x00000000 0x0050 multi-driver enable register pio_mder write-only ? 0x0054 multi-driver disable register pio_mddr write-only ? 0x0058 multi-driver status register pio_mdsr read-only 0x00000000 0x005c reserved ? ? ? 0x0060 pull-up disable register pio_pudr write-only ? 0x0064 pull-up enable register pio_puer write-only ? 0x0068 pad pull-up status register pio_pusr read-only (2) 0x006c reserved ? ? ?
594 sam4cp [datasheet] 43051e?atpl?08/14 0x0070 peripheral select register 1 pio_abcdsr1 read/write 0x00000000 0x0074 peripheral select register 2 pio_abcdsr2 read/write 0x00000000 0x0078 - 0x007c reserved ? ? ? 0x0080 input filter slow clock disable register pio_ifscdr write-only ? 0x0084 input filter slow clock enable register pio_ifscer write-only ? 0x0088 input filter slow clock status register pio_ifscsr read-only 0x00000000 0x008c slow clock divider debouncing register pio_scdr read/write 0x00000000 0x0090 pad pull-down disable register pio_ppddr write-only ? 0x0094 pad pull-down enable register pio_ppder write-only ? 0x0098 pad pull-down status register pio_ppdsr read-only (2) 0x009c reserved ? ? ? 0x00a0 output write enable pio_ower write-only ? 0x00a4 output write disable pio_owdr write-only ? 0x00a8 output write status register pio_owsr read-only 0x00000000 0x00ac reserved ? ? ? 0x00b0 additional interrupt modes enable register pio_aimer write-only ? 0x00b4 additional interrupt modes disable register pio_aimdr write-only ? 0x00b8 additional interrupt modes mask register pio_aimmr read-only 0x00000000 0x00bc reserved ? ? ? 0x00c0 edge select register pio_esr write-only ? 0x00c4 level select register pio_lsr write-only ? 0x00c8 edge/level status register pio_elsr read-only 0x00000000 0x00cc reserved ? ? ? 0x00d0 falling edge/low-level select register pio_fellsr write-only ? 0x00d4 rising edge/ high-level select register pio_rehlsr write-only ? 0x00d8 fall/rise - low/high status register pio_frlhsr read-only 0x00000000 0x00dc reserved ? ? ? 0x00e0 reserved ? ? ? 0x00e4 write protection mode register pio_wpmr read/write 0x0 0x00e8 write protection status register pio_wpsr read-only 0x0 0x00ec - 0x00fc reserved ? ? ? 0x0100 schmitt trigger register pio_schmitt read/write 0x00000000 0x0104 - 0x010c reserved ? ? ? 0x0110 reserved ? ? ? 0x0114 reserved ? ? ? table 32-3. register mapping (1) (continued) offset register name access reset
595 sam4cp [datasheet] 43051e?atpl?08/14 notes: 1. if an offset is not listed in the table it must be considered as reserved. 2. reset value depends on the product implementation. 3. pio_odsr is read-only or read/write depending on pio_owsr i/o lines. 4. reset value of pio_pdsr depends on the level of the i/o lines. reading the i/o line levels requires the clock of the pio controller to be enabled, otherwise pio_pdsr reads the levels present on the i/o line at the time the clock was disabled. 5. pio_isr is reset at 0x0. however, the first read of the register may read a different value as input changes may have occurred. 0x0118 i/o drive register 1 pio_driver1 read/write 0xaaaaaaaa 0x011c i/o drive register 2 pio_driver2 read/write 0xaaaaaaaa 0x0120 - 0x014c reserved ? ? ? table 32-3. register mapping (1) (continued) offset register name access reset
596 sam4cp [datasheet] 43051e?atpl?08/14 32.6.1 pio enable register name: pio_per address: 0x400e0e00 (pioa), 0x400e1000 (piob), 0x4800c000 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: pio enable 0: no effect. 1: enables the pio to control the corresponding pin (disables peripheral control of the pin). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
597 sam4cp [datasheet] 43051e?atpl?08/14 32.6.2 pio disable register name: pio_pdr address: 0x400e0e04 (pioa), 0x400e1004 (piob), 0x4800c004 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: pio disable 0: no effect. 1: disables the pio from controlling the corresponding pin (enables peripheral control of the pin). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
598 sam4cp [datasheet] 43051e?atpl?08/14 32.6.3 pio status register name: pio_psr address: 0x400e0e08 (pioa), 0x400e1008 (piob), 0x4800c008 (pioc) access: read-only ? p0-p31: pio status 0: pio is inactive on the corresponding i/o line (peripheral is active). 1: pio is active on the corresponding i/o line (peripheral is inactive). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
599 sam4cp [datasheet] 43051e?atpl?08/14 32.6.4 pio output enable register name: pio_oer address: 0x400e0e10 (pioa), 0x400e1010 (piob), 0x4800c010 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: output enable 0: no effect. 1: enables the output on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
600 sam4cp [datasheet] 43051e?atpl?08/14 32.6.5 pio output disable register name: pio_odr address: 0x400e0e14 (pioa), 0x400e1014 (piob), 0x4800c014 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: output disable 0: no effect. 1: disables the output on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
601 sam4cp [datasheet] 43051e?atpl?08/14 32.6.6 pio output status register name: pio_osr address: 0x400e0e18 (pioa), 0x400e1018 (piob), 0x4800c018 (pioc) access: read-only ? p0-p31: output status 0: the i/o line is a pure input. 1: the i/o line is enabled in output. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
602 sam4cp [datasheet] 43051e?atpl?08/14 32.6.7 pio input filter enable register name: pio_ifer address: 0x400e0e20 (pioa), 0x400e1020 (piob), 0x4800c020 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: input filter enable 0: no effect. 1: enables the input glitch filter on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
603 sam4cp [datasheet] 43051e?atpl?08/14 32.6.8 pio input filter disable register name: pio_ifdr address: 0x400e0e24 (pioa), 0x400e1024 (piob), 0x4800c024 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: input filter disable 0: no effect. 1: disables the input glitch filter on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
604 sam4cp [datasheet] 43051e?atpl?08/14 32.6.9 pio input filter status register name: pio_ifsr address: 0x400e0e28 (pioa), 0x400e1028 (piob), 0x4800c028 (pioc) access: read-only ? p0-p31: input filer status 0: the input glitch filter is disabled on the i/o line. 1: the input glitch filter is enabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
605 sam4cp [datasheet] 43051e?atpl?08/14 32.6.10 pio set output data register name: pio_sodr address: 0x400e0e30 (pioa), 0x400e1030 (piob), 0x4800c030 (pioc) access: write-only ? p0-p31: set output data 0: no effect. 1: sets the data to be driven on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
606 sam4cp [datasheet] 43051e?atpl?08/14 32.6.11 pio clear output data register name: pio_codr address: 0x400e0e34 (pioa), 0x400e1034 (piob), 0x4800c034 (pioc) access: write-only ? p0-p31: clear output data 0: no effect. 1: clears the data to be driven on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
607 sam4cp [datasheet] 43051e?atpl?08/14 32.6.12 pio output data status register name: pio_odsr address: 0x400e0e38 (pioa), 0x400e1038 (piob), 0x4800c038 (pioc) access: read-only or read/write ? p0-p31: output data status 0: the data to be driven on the i/o line is 0. 1: the data to be driven on the i/o line is 1. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
608 sam4cp [datasheet] 43051e?atpl?08/14 32.6.13 pio pin data status register name: pio_pdsr address: 0x400e0e3c (pioa), 0x400e103c (piob), 0x4800c03c (pioc) access: read-only ? p0-p31: output data status 0: the i/o line is at level 0. 1: the i/o line is at level 1. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
609 sam4cp [datasheet] 43051e?atpl?08/14 32.6.14 pio interrupt enable register name: pio_ier address: 0x400e0e40 (pioa), 0x400e1040 (piob), 0x4800c040 (pioc) access: write-only ? p0-p31: input change interrupt enable 0: no effect. 1: enables the input change interrupt on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
610 sam4cp [datasheet] 43051e?atpl?08/14 32.6.15 pio interrupt disable register name: pio_idr address: 0x400e0e44 (pioa), 0x400e1044 (piob), 0x4800c044 (pioc) access: write-only ? p0-p31: input change interrupt disable 0: no effect. 1: disables the input change interrupt on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
611 sam4cp [datasheet] 43051e?atpl?08/14 32.6.16 pio interrupt mask register name: pio_imr address: 0x400e0e48 (pioa), 0x400e1048 (piob), 0x4800c048 (pioc) access: read-only ? p0-p31: input change interrupt mask 0: input change interrupt is disabled on the i/o line. 1: input change interrupt is enabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
612 sam4cp [datasheet] 43051e?atpl?08/14 32.6.17 pio interrupt status register name: pio_isr address: 0x400e0e4c (pioa), 0x400e104c (piob), 0x4800c04c (pioc) access: read-only ? p0-p31: input change interrupt status 0: no input change has been detected on the i/o line since pio_isr was last read or since reset. 1: at least one input change has been detected on the i/o line since pio_isr was last read or since reset. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
613 sam4cp [datasheet] 43051e?atpl?08/14 32.6.18 pio multi-driver enable register name: pio_mder address: 0x400e0e50 (pioa), 0x400e1050 (piob), 0x4800c050 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: multi-drive enable 0: no effect. 1: enables multi-drive on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
614 sam4cp [datasheet] 43051e?atpl?08/14 32.6.19 pio multi-driver disable register name: pio_mddr address: 0x400e0e54 (pioa), 0x400e1054 (piob), 0x4800c054 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: multi-drive disable 0: no effect. 1: disables multi-drive on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
615 sam4cp [datasheet] 43051e?atpl?08/14 32.6.20 pio multi-driver status register name: pio_mdsr address: 0x400e0e58 (pioa), 0x400e1058 (piob), 0x4800c058 (pioc) access: read-only ? p0-p31: multi-drive status 0: the multi-drive is disabled on the i/o line. the pin is driven at high- and low-level. 1: the multi-drive is enabled on the i/o line. the pin is driven at low-level only. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
616 sam4cp [datasheet] 43051e?atpl?08/14 32.6.21 pio pull-up disable register name: pio_pudr address: 0x400e0e60 (pioa), 0x400e1060 (piob), 0x4800c060 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: pull-up disable 0: no effect. 1: disables the pull-up resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
617 sam4cp [datasheet] 43051e?atpl?08/14 32.6.22 pio pull-up enable register name: pio_puer address: 0x400e0e64 (pioa), 0x400e1064 (piob), 0x4800c064 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: pull-up enable 0: no effect. 1: enables the pull-up resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
618 sam4cp [datasheet] 43051e?atpl?08/14 32.6.23 pio pull-up status register name: pio_pusr address: 0x400e0e68 (pioa), 0x400e1068 (piob), 0x4800c068 (pioc) access: read-only ? p0-p31: pull-up status 0: pull-up resistor is enabled on the i/o line. 1: pull-up resistor is disabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
619 sam4cp [datasheet] 43051e?atpl?08/14 32.6.24 pio peripheral abcd select register 1 name: pio_abcdsr1 access: read/write this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: peripheral select if the same bit is set to 0 in pio_abcdsr2: 0: assigns the i/o line to the peripheral a function. 1: assigns the i/o line to the peripheral b function. if the same bit is set to 1 in pio_abcdsr2: 0: assigns the i/o line to the peripheral c function. 1: assigns the i/o line to the peripheral d function. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
620 sam4cp [datasheet] 43051e?atpl?08/14 32.6.25 pio peripheral abcd select register 2 name: pio_abcdsr2 access: read/write this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: peripheral select if the same bit is set to 0 in pio_abcdsr1: 0: assigns the i/o line to the peripheral a function. 1: assigns the i/o line to the peripheral c function. if the same bit is set to 1 in pio_abcdsr1: 0: assigns the i/o line to the peripheral b function. 1: assigns the i/o line to the peripheral d function. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
621 sam4cp [datasheet] 43051e?atpl?08/14 32.6.26 pio input filter slow clock disable register name: pio_ifscdr address: 0x400e0e80 (pioa), 0x400e1080 (piob), 0x4800c080 (pioc) access: write-only ? p0-p31: peripheral clock glitch filtering select 0: no effect. 1: the glitch filter is able to filter glitches with a duration < t peripheral clock /2. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
622 sam4cp [datasheet] 43051e?atpl?08/14 32.6.27 pio input filter slow clock enable register name: pio_ifscer address: 0x400e0e84 (pioa), 0x400e1084 (piob), 0x4800c084 (pioc) access: write-only ? p0-p31: slow clock debouncing filtering select 0: no effect. 1: the debouncing filter is able to filter pulses with a duration < t div_slck /2. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
623 sam4cp [datasheet] 43051e?atpl?08/14 32.6.28 pio input filter slow clock status register name: pio_ifscsr address: 0x400e0e88 (pioa), 0x400e1088 (piob), 0x4800c088 (pioc) access: read-only ? p0-p31: glitch or debouncing filter selection status 0: the glitch filter is able to filter glitches with a duration < t peripheral clock /2. 1: the debouncing filter is able to filter pulses with a duration < t div_slck /2. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
624 sam4cp [datasheet] 43051e?atpl?08/14 32.6.29 pio slow clock divider debouncing register name: pio_scdr address: 0x400e0e8c (pioa), 0x400e108c (piob), 0x4800c08c (pioc) access: read/write ? div: slow clock divider selection for debouncing t div_slck = ((div+1) * 2) * t slck 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? div 76543210 div
625 sam4cp [datasheet] 43051e?atpl?08/14 32.6.30 pio pad pull-down disable register name: pio_ppddr address: 0x400e0e90 (pioa), 0x400e1090 (piob), 0x4800c090 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: pull-down disable 0: no effect. 1: disables the pull-down resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
626 sam4cp [datasheet] 43051e?atpl?08/14 32.6.31 pio pad pull-down enable register name: pio_ppder address: 0x400e0e94 (pioa), 0x400e1094 (piob), 0x4800c094 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: pull-down enable 0: no effect. 1: enables the pull-down resistor on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
627 sam4cp [datasheet] 43051e?atpl?08/14 32.6.32 pio pad pull-down status register name: pio_ppdsr address: 0x400e0e98 (pioa), 0x400e1098 (piob), 0x4800c098 (pioc) access: read-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: pull-down status 0: pull-down resistor is enabled on the i/o line. 1: pull-down resistor is disabled on the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
628 sam4cp [datasheet] 43051e?atpl?08/14 32.6.33 pio output write enable register name: pio_ower address: 0x400e0ea0 (pioa), 0x400e10a0 (piob), 0x4800c0a0 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: output write enable 0: no effect. 1: enables writing pio_odsr for the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
629 sam4cp [datasheet] 43051e?atpl?08/14 32.6.34 pio output write disable register name: pio_owdr address: 0x400e0ea4 (pioa), 0x400e10a4 (piob), 0x4800c0a4 (pioc) access: write-only this register can only be written if the wpen bit is cleared in ?pio write protection mode register? . ? p0-p31: output write disable 0: no effect. 1: disables writing pio_odsr for the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
630 sam4cp [datasheet] 43051e?atpl?08/14 32.6.35 pio output write status register name: pio_owsr address: 0x400e0ea8 (pioa), 0x400e10a8 (piob), 0x4800c0a8 (pioc) access: read-only ? p0-p31: output write status 0: writing pio_odsr does not affect the i/o line. 1: writing pio_odsr affects the i/o line. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
631 sam4cp [datasheet] 43051e?atpl?08/14 32.6.36 pio additional interrupt modes enable register name: pio_aimer address: 0x400e0eb0 (pioa), 0x400e10b0 (piob), 0x4800c0b0 (pioc) access: write-only ? p0-p31: additional interrupt modes enable 0: no effect. 1: the interrupt source is the event described in pio_elsr and pio_frlhsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
632 sam4cp [datasheet] 43051e?atpl?08/14 32.6.37 pio additional interrupt modes disable register name: pio_aimdr address: 0x400e0eb4 (pioa), 0x400e10b4 (piob), 0x4800c0b4 (pioc) access: write-only ? p0-p31: additional interrupt modes disable 0: no effect. 1: the interrupt mode is set to the default interrupt mode (both-edge detection). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
633 sam4cp [datasheet] 43051e?atpl?08/14 32.6.38 pio additional interrupt modes mask register name: pio_aimmr address: 0x400e0eb8 (pioa), 0x400e10b8 (piob), 0x4800c0b8 (pioc) access: read-only ? p0-p31: io line index selects the io event type triggering an interrupt. 0: the interrupt source is a both-edge detection event. 1: the interrupt source is described by the registers pio_elsr and pio_frlhsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
634 sam4cp [datasheet] 43051e?atpl?08/14 32.6.39 pio edge select register name: pio_esr address: 0x400e0ec0 (pioa), 0x400e10c0 (piob), 0x4800c0c0 (pioc) access: write-only ? p0-p31: edge interrupt selection 0: no effect. 1: the interrupt source is an edge-detection event. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
635 sam4cp [datasheet] 43051e?atpl?08/14 32.6.40 pio level select register name: pio_lsr address: 0x400e0ec4 (pioa), 0x400e10c4 (piob), 0x4800c0c4 (pioc) access: write-only ? p0-p31: level interrupt selection 0: no effect. 1: the interrupt source is a level-detection event. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
636 sam4cp [datasheet] 43051e?atpl?08/14 32.6.41 pio edge/level status register name: pio_elsr address: 0x400e0ec8 (pioa), 0x400e10c8 (piob), 0x4800c0c8 (pioc) access: read-only ? p0-p31: edge/level interrupt source selection 0: the interrupt source is an edge-detection event. 1: the interrupt source is a level-detection event. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
637 sam4cp [datasheet] 43051e?atpl?08/14 32.6.42 pio falling edge/low-level select register name: pio_fellsr address: 0x400e0ed0 (pioa), 0x400e10d0 (piob), 0x4800c0d0 (pioc) access: write-only ? p0-p31: falling edge/low-level interrupt selection 0: no effect. 1: the interrupt source is set to a falling edge detection or low-level detection event, depending on pio_elsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
638 sam4cp [datasheet] 43051e?atpl?08/14 32.6.43 pio rising edge/high-level select register name: pio_rehlsr address: 0x400e0ed4 (pioa), 0x400e10d4 (piob), 0x4800c0d4 (pioc) access: write-only ? p0-p31: rising edge/high-level interrupt selection 0: no effect. 1: the interrupt source is set to a rising edge detection or high-level detection event, depending on pio_elsr. 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
639 sam4cp [datasheet] 43051e?atpl?08/14 32.6.44 pio fall/rise - low/high status register name: pio_frlhsr address: 0x400e0ed8 (pioa), 0x400e10d8 (piob), 0x4800c0d8 (pioc) access: read-only ? p0-p31: edge/level interrupt source selection 0: the interrupt source is a falling edge detection (if pio_elsr = 0) or low-level detection event (if pio_elsr = 1). 1: the interrupt source is a rising edge detection (if pio_elsr = 0) or high-level detection event (if pio_elsr = 1). 31 30 29 28 27 26 25 24 p31 p30 p29 p28 p27 p26 p25 p24 23 22 21 20 19 18 17 16 p23 p22 p21 p20 p19 p18 p17 p16 15 14 13 12 11 10 9 8 p15 p14 p13 p12 p11 p10 p9 p8 76543210 p7 p6 p5 p4 p3 p2 p1 p0
640 sam4cp [datasheet] 43051e?atpl?08/14 32.6.45 pio write protection mode register name: pio_wpmr address: 0x400e0ee4 (pioa), 0x400e10e4 (piob), 0x4800c0e4 (pioc) access: read/write ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x50494f (?pio? in ascii). 1: enables the write protection if wpkey corresponds to 0x50494f (?pio? in ascii). see section 32.5.14 ?register write protection? for the list of registers that can be protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x50494f passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
641 sam4cp [datasheet] 43051e?atpl?08/14 32.6.46 pio write protection status register name: pio_wpsr address: 0x400e0ee8 (pioa), 0x400e10e8 (piob), 0x4800c0e8 (pioc) access: read-only ? wpvs: write protection violation status 0: no write protection violation has occurred since the last read of the pio_wpsr. 1: a write protection violation has occurred since the last read of the pio_wpsr. if this vi olation is an unauthorized attempt to write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
642 sam4cp [datasheet] 43051e?atpl?08/14 32.6.47 pio schmitt trigger register name: pio_schmitt address: 0x400e0f00 (pioa), 0x400e1100 (piob), 0x4800c100 (pioc) access: read/write ? schmittx [x=0..31]: schmitt trigger control 0: schmitt trigger is enabled. 1: schmitt trigger is disabled. 31 30 29 28 27 26 25 24 schmitt31 schmitt30 schmitt29 schmitt28 schmitt27 schmitt26 schmitt25 schmitt24 23 22 21 20 19 18 17 16 schmitt23 schmitt22 schmitt21 schmitt20 schmitt19 schmitt18 schmitt17 schmitt16 15 14 13 12 11 10 9 8 schmitt15 schmitt14 schmitt13 schmitt12 schmitt11 schmitt10 schmitt9 schmitt8 76543210 schmitt7 schmitt6 schmitt5 schmitt4 schmitt3 schmitt2 schmitt1 schmitt0
643 sam4cp [datasheet] 43051e?atpl?08/14 32.6.48 pio i/o drive register 1 name: pio_driver1 address: 0x400e0f18 (pioa), 0x400e1118 (piob), 0x4800c118 (pioc) access: read/write ? linex [x=0..15]: drive of pio line x 31 30 29 28 27 26 25 24 line15 line14 line13 line12 23 22 21 20 19 18 17 16 line11 line10 line9 line8 15 14 13 12 11 10 9 8 line7 line6 line5 line4 76543210 line3 line2 line1 line0 value name description 0 hi_drive high drive 1 me_drive medium drive 2 lo_drive low drive 3 reserved
644 sam4cp [datasheet] 43051e?atpl?08/14 32.6.49 pio i/o drive register 2 name: pio_driver2 address: 0x400e0f1c (pioa), 0x400e111c (piob), 0x4800c11c (pioc) access: read/write ? linex [x=16..31]: drive of pio line x 31 30 29 28 27 26 25 24 line31 line30 line29 line28 23 22 21 20 19 18 17 16 line27 line26 line25 line24 15 14 13 12 11 10 9 8 line23 line22 line21 line20 76543210 line19 line18 line17 line16 value name description 0 hi_drive high drive 1 me_drive medium drive 2 lo_drive low drive 3 reserved
645 sam4cp [datasheet] 43051e?atpl?08/14 33. serial peripheral interface (spi) 33.1 description the serial peripheral interface (spi) circuit is a synchrono us serial data link that provides communication with external devices in master or slave mode. it also enables communication between processors if an external processor is connected to the system. the serial peripheral interface is essentially a shift register that serially transmits data bits to other spis. during a data transfer, one spi system acts as the ?master?' which controls the data flow, while the other devices act as ?slaves'' which have data shifted into and out by the master. different cpus can take turn being masters (multiple master protocol, contrary to single master protocol where one cpu is always the master while all of the ot hers are always slaves). one master can simultaneously shift data into multiple slaves. however, only one slave can drive its output to write data back to the master at any given time. a slave device is selected when the master asserts its nss signal. if multiple slave devices exist, the master generates a separate slave select signal for each slave (npcs). the spi system consists of two data lines and two control lines: ? master out slave in (mosi): this data line supplies the output data from the master shifted into the input(s) of the slave(s). ? master in slave out (miso): this data line supplies the output data from a slave to the input of the master. there may be no more than one slave transmitting data during any particular transfer. ? serial clock (spck): this control line is driven by the master and regulates the flow of the data bits. the master can transmit data at a variety of baud rates; there is one spck pulse for each bit that is transmitted. ? slave select (nss): this control line allows slaves to be turned on and off by hardware. 33.2 embedded characteristics ? master or slave serial peripheral bus interface ? 8-bit to 16-bit programmable data length per chip select ? programmable phase and polarity per chip select ? programmable transfer delay between consecutive transfers and delay before spi clock per chip select ? programmable delay between chip selects ? selectable mode fault detection ? master mode can drive spck up to peripheral clock ? master mode bit rate can be independent of the processor/peripheral clock ? slave mode operates on spck, asynchronously with core and bus clock ? four chip selects with external decoder support allow communication with up to 15 peripherals ? communication with serial external devices supported ? serial memories, such as dataflash and 3-wire eeproms ? serial peripherals, such as adcs, dacs, lcd controllers, can controllers and sensors ? external coprocessors ? connection to pdc channel capabilities optimizing data transfers ? one channel for the receiver ? one channel for the transmitter ? register write protection
646 sam4cp [datasheet] 43051e?atpl?08/14 33.3 block diagram figure 33-1. block diagram 33.4 application block diagram figure 33-2. application block diagram: single master/multiple slave implementation pdc spi peripheral bridge pmc peripheral clock bus clock ahb matrix trigger events spi master spck miso mosi npcs0 npcs1 npcs2 spck miso mosi nss slave 0 spck miso mosi nss slave 1 spck miso mosi nss slave 2 nc npcs3
647 sam4cp [datasheet] 43051e?atpl?08/14 33.5 signal description 33.6 product dependencies 33.6.1 i/o lines the pins used for interfacing the compliant external devices can be multiplexed with pio lines. the programmer must first program the pio controllers to assign the spi pins to their peripheral functions. 33.6.2 power management the spi can be clocked through the power management controller (pmc), thus the programmer must first configure the pmc to enable the spi clock. 33.6.3 interrupt the spi interface has an interrupt line connected to the interrupt controller. handling the spi interrupt requires programming the interrupt controller before configuring the spi. 33.6.4 peripheral dma controller (pdc) the spi interface can be used in conjunction with the pdc in order to reduce processor overhead. for a full description of the pdc, refer to the corresponding section in the full datasheet. table 33-1. signal description pin name pin description type master slave miso master in slave out input output mosi master out slave in output input spck serial clock output input npcs1 - npcs3 peripheral chip selects output unused npcs0/nss peripheral chip select/slave select output input table 33-2. i/o lines instance signal i/o line peripheral spi1 spi1_miso pc3 a spi1 spi1_mosi pc4 a spi1 spi1_npcs0 pc2 a spi1 spi1_npcs1 pc6 b spi1 spi1_npcs2 pc7 b spi1 spi1_npcs3 pc8 b spi1 spi1_spck pc5 a table 33-3. peripheral ids instance id spi1 40
648 sam4cp [datasheet] 43051e?atpl?08/14 33.7 functional description 33.7.1 modes of operation the spi operates in master mode or in slave mode. ? the spi operates in master mode by writing a 1 to the mstr bit in the spi mode register (spi_mr): ? the pins npcs0 to npcs3 are all configured as outputs ? the spck pin is driven ? the miso line is wired on the receiver input ? the mosi line is driven as an output by the transmitter. ? the spi operates in slave mode if the mstr bit in the spi_mr is written to 0: ? the miso line is driven by the transmitter output ? the mosi line is wired on the receiver input ? the spck pin is driven by the transmitter to synchronize the receiver. ? the npcs0 pin becomes an input, and is used as a slave select signal (nss). ? the pins npcs0 to npcs3 are not driven and can be used for other purposes. the data transfers are identically programmable for both modes of operations. the baud rate generator is activated only in master mode. 33.7.2 data transfer four combinations of polarity and phase are available for data transfers. the clock polarity is programmed with the cpol bit in the spi chip select register (spi_csr). the clock phase is programmed with the ncpha bit. these two parameters determine the edges of the cl ock signal on which data is driven and sampled. each of the two parameters has two possible states, resulting in four possible combinations that are incompatible with one another. consequently, a master/slave pair must use the same parameter pair values to communicate. if multiple slaves are connected and require different configurations, the master must reconfigure itself each time it needs to communicate with a different slave. table 33-4 shows the four modes and corresponding parameter settings. table 33-4. spi bus protocol mode spi mode cpol ncpha shift spck edge capture spck edge spck inactive level 0 0 1 falling rising low 1 0 0 rising falling low 2 1 1 rising falling high 3 1 0 falling rising high
649 sam4cp [datasheet] 43051e?atpl?08/14 figure 33-3 and figure 33-4 show examples of data transfers. figure 33-3. spi transfer format (ncpha = 1, 8 bits per transfer) figure 33-4. spi transfer format (ncpha = 0, 8 bits per transfer) 6 * spck (cpol = 0) spck (cpol = 1) mosi (from master) miso (from slave) nss (to slave) s pck cycle (for reference) msb msb lsb lsb 6 6 5 5 4 4 3 3 2 2 1 1 1 2345 78 6 * not defined * spck (cpol = 0) spck (cpol = 1) 1 2345 7 mosi (from master) miso (from slave) nss (to slave) s pck cycle (for reference) 8 msb msb lsb lsb 6 6 5 5 4 4 3 3 1 1 2 2 6 * not defined
650 sam4cp [datasheet] 43051e?atpl?08/14 33.7.3 master mode operations when configured in master mode, the spi operates on the clock generated by the internal programmable baud rate generator. it fully controls the data transfers to and from the slave(s) connected to the spi bus. the spi drives the chip select line to the slave and the serial clock signal (spck). the spi features two holding registers, the transmit data register (spi_tdr) and the receive data register (spi_rdr), and a single shift register. the holding registers maintain the data flow at a constant rate. after enabling the spi, a data transfer starts when the processor writes to the spi_tdr. the written data is immediately transferred in the shift register and the transfer on the spi bu s starts. while the data in the shift register is shifted on the mosi line, the miso line is sampled and shifted in the shift register. data cannot be loaded in the spi_rdr without transmitting data. if there is no data to transmit, dummy data can be used (spi_tdr filled with ones). when the spi_mr.wdrbt bit is set, new data cannot be transmitted if the spi_rdr has not been read. if receiving mode is not required, for example when communicating with a slave receiver only (such as an lcd), the receive status flags in the spi status register (spi_sr) can be discarded. before writing the spi_tdr, the pcs field in the mode register (spi_mr) must be set in order to select a slave. if new data is written in spi_tdr during the transfer, it is kept in the spi_tdr until the current transfer is completed. then, the received data is transferred from the shift register to the spi_rdr, the data in the spi_tdr is loaded in the shift register and a new transfer starts. the transfer of data written in the spi_tdr to the shift register is indicated by the transmit data register empty (tdre) bit in the spi_sr. when new data is written in the spi_tdr, this bit is cleared. the tdre bit is used to trigger the transmit pdc channel. the end of transfer is indicated by the txempty flag in the spi_sr. if a transfer delay (dlybct) is greater than 0 for the last transfer, txempty is set after the completion of this delay. the peripheral clock can be switched off at this time. the transfer of received data from the shift register to the spi_rdr is indicated by the receive data register full (rdrf) bit in the spi_sr. when the received data is read, the rdrf bit is cleared. if the spi_rdr has not been read before new data is received, the overrun error (ovres) bit in spi_sr is set. as long as this flag is set, data is loaded in the spi_rdr. the user has to read the status register to clear the ovres bit. figure 33-5 , shows a block diagram of the spi when operating in master mode. figure 33-6 on page 652 shows a flow chart describing how transfers are handled.
651 sam4cp [datasheet] 43051e?atpl?08/14 33.7.3.1 master mode block diagram figure 33-5. master mode block diagram shift register spck mosi lsb msb miso spi_rdr rd spi clock tdre spi_tdr td rdrf ovres spi_csrx cpol ncpha bits peripheral clock baud rate generator spi_csrx scbr npcsx npcs0 npcs0 0 1 ps spi_mr pcs spi_tdr pcs modf current peripheral spi_rdr pcs spi_csrx csaat pcsdec modfdis mstr
652 sam4cp [datasheet] 43051e?atpl?08/14 33.7.3.2 master mode flow diagram figure 33-6. master mode flow diagram spi enable csaat ? ps ? 1 0 0 1 1 npcs = spi_tdr(pcs) npcs = spi_mr(pcs) delay dlybs serializer = spi_tdr(td) tdre = 1 data transfer spi_rdr(rd) = serializer rdrf = 1 tdre ? npcs deasserted delay dlybcs fixed peripheral variable peripheral delay dlybct 0 1 csaat ? 0 tdre ? 1 0 ps ? 0 1 spi_tdr(pcs) = npcs ? no yes spi_mr(pcs) = npcs ? no npcs deasserted delay dlybcs npcs = spi_tdr(pcs) npcs deasserted delay dlybcs npcs = spi_mr(pcs), spi_tdr(pcs) fixed peripheral variable peripheral - npcs defines the current chip select - csaat, dlybs, dlybct refer to the fields of the chip select register corresponding to the current chip select
653 sam4cp [datasheet] 43051e?atpl?08/14 figure 33-7 shows the behavior of transmit data register empty (tdre), receive data register (rdrf) and transmission register empty (txempty) status flags within the spi_sr during an 8-bit data transfer in fixed mode without the pdc involved. figure 33-7. status register flags behavior figure 33-8 shows the behavior of transmission register empty (txempty), end of rx buffer (endrx), end of tx buffer (endtx), rx buffer full (rxbuff) and tx buffer empty (txbufe) status flags within the spi_sr during an 8-bit data transfer in fixed mode with the pdc involved. the pdc is programmed to transfer and receive three units of data. the next pointer and counter are not used. the rdrf and tdre are not shown because these flags are managed by the pdc when using the pdc. figure 33-8. pdc status register flags behavior 6 spck mosi ( from master) miso (from slave) npcs0 msb msb lsb lsb 6 6 5 5 4 4 3 3 2 2 1 1 1 2345 78 6 rdrf tdre txempty write in spi_tdr rdr read shift register empty 654321 spck mosi (from master) npcs0 msb lsb 654321 12 3 endtx txempty msb lsb 654321 654321 miso (from slave) 654321 654321 endrx txbufe rxbuff tdre (not required i f pdc is used) pdc loads first byte pdc loads 2nd byte (double buffer effect) pdc loads last byte msb msb msb msb lsb lsb lsb lsb
654 sam4cp [datasheet] 43051e?atpl?08/14 33.7.3.3 clock generation the spi baud rate clock is generated by dividing the peripheral clock, by a value between 1 and 255. if the scbr field in the spi_csr is programmed to 1, the operating baud rate is peripheral clock (see the ?electrical characteristics? section for the spck maximum frequency). triggering a transfer while scbr is at 0 can lead to unpredictable results . at reset, scbr is 0 and the user has to program it to a valid value before performing the first transfer. the divisor can be defined independently for each chip select, as it has to be programmed in the scbr field. this allows the spi to automatically adapt the baud rate for each interfaced peripheral without reprogramming. 33.7.3.4 transfer delays figure 33-9 shows a chip select transfer change and consecutive transfers on the same chip select. three delays can be programmed to modify the transfer waveforms: ? delay between the chip selects - programmable only once for all chip selects by writing the dlybcs field in the spi_mr. the spi slave device deactivation delay is managed through dlybcs. if there is only one spi slave device connected to the master, the dlybcs field does not need to be configured. if several slave devices are connected to a master, dlybcs must be configured depending on the highest deactivation delay. refer to the spi slave device electrical characteristics. ? delay before spck - independently programmable for each chip select by writing the dlybs field. the spi slave device activation delay is managed through dlybs. refer to the spi slave device electrical characteristics to define dlybs. ? delay between consecutive transfers - independently programmable for each chip select by writing the dlybct field. the time required by the spi slave device to process received data is managed through dlybct. this time depends on the spi slave system activity. these delays allow the spi to be adapted to the interfaced peripherals and their speed and bus release time. figure 33-9. programmable delays 33.7.3.5 peripheral selection the serial peripherals are selected through the assertion of the npcs0 to npcs3 signals. by default, all the npcs signals are high before and after each transfer. ? fixed peripheral select mode : spi exchanges data with only one peripheral. fixed peripheral select mode is enabled by writing the ps bit to zero in the spi_mr. in this case, the current peripheral is defined by the pcs field in the spi_mr and the pcs field in the spi_tdr has no effect. ? variable peripheral select mode: data can be exchanged with more than one peripheral without having to reprogram the npcs field in the spi_mr. variable peripheral select mode is enabled by setting ps bit to 1 in the spi_mr. the pcs field in the spi_tdr is used to select the current peripheral. this means that the peripheral selection can be defined for each new data. the value to write in the spi_tdr register as the following format. dlybcs dlybs dlybct dlybct chip select 1 chip select 2 spck
655 sam4cp [datasheet] 43051e?atpl?08/14 [xxxxxxx(7-bit) + lastxfer(1-bit) (1) + xxxx(4-bit) + pcs (4-bit) + data (8 to 16-bit)] with pcs equals the chip select to assert, as defined in section 33.8.4 ?spi transmit data register? and lastxfer bit at 0 or 1 depending on the csaat bit. note:1. optional. csaat, lastxfer and csnaat bits are discussed in section 33.7.3.9 ?peripheral deselection with pdc? . if lastxfer is used, the command must be issued before writing the last character. instead of lastxfer, the user can use the spidis command. after the end of the pdc transfer, it is necessary to wait for the txempty flag and then write spidis into the spi control register (spi_cr). this does not change the configuration register values. the npcs is disabled after the last character transfer. then, another pdc transfer can be started if the spien has previously been written in the spi_cr. 33.7.3.6 spi peripheral dma controller (pdc) in both fixed and variable peripheral select modes, the peripheral dma controller (pdc) can be used to reduce processor overhead. the fixed peripheral selection allows buffer transfers with a single peripheral. using the pdc is an optimal means, as the size of the data transfer between the memory and the spi is either 8 bits or 16 bits. however, if the peripheral selection is modified, the spi_mr must be reprogrammed. the variable peripheral selection allows buffer transfers with multiple peripherals without reprogramming the spi_mr. data written in the spi_tdr is 32 bits wide and defines th e real data to be transmitted and the destination peripheral. using the pdc in this mode requires 32-bit wide buffers, with the data in the lsbs and the pcs and lastxfer fields in the msbs. however, the spi still controls the number of bits (8 to16) to be transferred through miso and mosi lines with the chip select configuration registers (spi_csrx). this is not the optimal means in terms of memory size for the buffers, but it provides a very effective means to exchange data with several peripherals without any intervention of the processor. transfer size depending on the data size to transmit, from 8 to 16 bits, the pdc manages automatically the type of pointer's size it has to point to. the pdc performs the following transfer, depending on the mode and number of bits per data. fixed mode: ? 8-bit data: byte transfer, pdc pointer address = address + 1 byte, pdc counter = counter - 1 ? 8-bit to 16-bit data: 2 bytes transfer. n-bit data transfer with don?t care data (msb) filled with 0?s, pdc pointer address = address + 2 bytes, pdc counter = counter - 1 variable mode: ? in variable mode, pdc pointer address = address + 4 bytes and pdc counter = counter - 1 for 8 to 16-bit transfer size. ? when using the pdc, the tdre and rdrf flags are handled by the pdc. the user?s application does not have to check these bits. only end of rx buffer (endrx), end of tx buffer (endtx), buffer full (rxbuff), tx buffer empty (txbufe) are significant. for further details about the peripheral dma controller and user interface, refer to the pdc section of the product datasheet. 33.7.3.7 peripheral chip select decoding the user can program the spi to operate with up to 15 slave peripherals by decoding the four chip select lines, npcs0 to npcs3 with an external decoder/demultiplexer. this can be enabled by writing a 1 to the pcsdec bit in the spi_mr.
656 sam4cp [datasheet] 43051e?atpl?08/14 when operating without decoding, the spi makes sure that in any case only one chip select line is activated, i.e., one npcs line driven low at a time. if two bits are defined low in a pcs field, only the lowest numbered chip select is driven low. when operating with decoding, the spi directly outputs the va lue defined by the pcs field on the npcs lines of either spi_mr or spi_tdr (depending on ps). as the spi sets a default value of 0xf on the chip select lines (i.e. all chip select lines at 1) when not processing any transfer, only 15 peripherals can be decoded. the spi has only four chip select regi sters. as a result, when external decoding is activated, each npcs chip select defines the characteristics of up to four peripherals. as an example, spi_crs0 defines the characteristics of the externally decoded peripherals 0 to 3, corresponding to the pcs values 0x0 to 0x3. consequently, the user has to make sure to connect compatible peripherals on the decoded chip select lines 0 to 3, 4 to 7, 8 to 11 and 12 to 14. figure 33-10 shows this type of implementation. if the csaat bit is used, with or without the pdc, the mode fault detection for npcs0 line must be disabled. this is not required for all other chip select lines since mode fault detection is only on npcs0. figure 33-10. chip select decoding application block diagram: single master/multiple slave implementation 33.7.3.8 peripheral deselection without pdc during a transfer of more than one unit of data on a chip select without the pdc, the spi_tdr is loaded by the processor, the tdre flag rises as soon as the content of the spi_tdr is transferred into the internal shift register. when this flag is detected high, the spi_tdr can be reloaded. if this reload by the processor occurs before the end of the current transfer and if the next transfer is performed on the same chip select as the current transfer, the chip select is not de-asserted between the two transfers. but depending on the application software handling the spi status register flags (by interrupt or polling method) or servicing other interrupts or other tasks, the processor may not reload the spi_tdr in time to keep the chip select active (low). a null delay between consecutive transfer (dlybct) value in the spi_csr, will give even less time for the processor to reload the spi_tdr. with some spi slave peripherals, if the chip select line must remain active (low) during a full set of transfers, communication errors can occur. to facilitate interfacing with such devices, the chip select register [csr0...csr3] can be programmed with the chip select active after transfer (csaat) bit to 1. this allows the chip select lines to remain in their current state (low = active) until a transfer to another chip select is required. even if the spi_tdr is not reloaded, the chip select remains active. to de-assert the chip select line at the end of the transfer, the last transfer (lastxfer) bit in the spi_mr must be set to 1 before writing the last data to transmit into the spi_tdr. spi master spck miso mosi npcs0 npcs1 npcs2 spck miso mosi nss slave 0 spck miso mosi nss slave 1 spck miso mosi nss slave 14 npcs3 decoded chip select lines external 1-of-n decoder/demultiplexer
657 sam4cp [datasheet] 43051e?atpl?08/14 33.7.3.9 peripheral deselection with pdc pdc provides faster reloads of the spi_tdr compared to software. however, depending on the system activity, it is not guaranteed that the spi_tdr is written with the next data before the end of the current transfer. consequently, data can be lost by the de-assertion of the npcs line for spi slave peripherals requiring the chip select line to remain active between two transfers. the only way to guarantee a safe transfer in this case is the use of the csaat and lastxfer bits. when the csaat bit is configured to 0, the npcs does not rise in all cases between two transfers on the same peripheral. during a transfer on a chip select, the tdre flag rises as soon as the content of the spi_tdr is transferred into the internal shift register. when this flag is detected, the spi_tdr can be reloaded. if this reload occurs before the end of the current transfer and if the next transfer is performed on the same chip select as the current transfer, the chip select is not de-asserted between the two transfers. this can lead to difficulties to interface with some serial peripherals requiring the chip select to be de-asserted after each tran sfer. to facilitate interfacing with such devices, the spi_csr can be programmed with the chip select not active after transfer (csnaat) bit to 1. this allows the chip select lines to be de-asserted systematically during a time ?dlybcs? (the value of the csnaat bit is processed only if the csaat bit is configured to 0 for the same chip select). figure 33-11 shows different peripheral deselection cases and the effect of the csaat and csnaat bits. figure 33-11. peripheral deselection a npcs[0..3] write spi_tdr tdre npcs[0..3] write spi_tdr tdre npcs[0..3] write spi_tdr tdre dlybcs pcs = a dlybcs dlybct a pcs = b b dlybcs pcs = a dlybcs dlybct a pcs = b b dlybcs dlybct pcs=a a dlybcs dlybct a pcs = a a a dlybct aa csaat = 0 and csnaat = 0 dlybct aa csaat = 1 and csnaat= 0 / 1 a dlybcs pcs = a dlybct aa csaat = 0 and csnaat = 1 npcs[0..3] write spi_tdr tdre pcs = a dlybct aa csaat = 0 and csnaat = 0
658 sam4cp [datasheet] 43051e?atpl?08/14 33.7.3.10 mode fault detection the spi has the capability to operate in multi-master environment. consequently, the npcs0/nss line must be monitored. if one of the masters on the spi bus is currently transmitting, the npcs0/nss line is low and the spi must not transmit any data. a mode fault is detected when the spi is programmed in master mode and a low level is driven by an external master on the npcs0/nss signal. in multi-master environment, npcs0, mosi, miso and spck pins must be configured in open drain (through the pio controller). when a mode fault is detected, the modf bit in the spi_sr is set until spi_sr is read and the spi is automatically disabled until it is re-enabled by writing a 1 to the spien bit in the spi_cr. by default, the mode fault detection is enabled. the user can disable it by setting the modfdis bit in the spi_mr. 33.7.4 spi slave mode when operating in slave mode, the spi processes data bits on the clock provided on the spi clock pin (spck). the spi waits until nss goes active before receiving the serial clock from an external master. when nss falls, the clock is validated and the data is loaded in the spi_rdr depending on the bits field configured in the spi_csr0. these bits are processed following a phase and a polarity defined respectively by the ncpha and cpol bits in the spi_csr0. note that bits, cpol and ncpha of the other chip select registers have no effect when the spi is programmed in slave mode. the bits are shifted out on the miso line and sampled on the mosi line. note: for more information on bits field, see also, the note (1) below the spi_csrx register bitmap ( section 33.8.9 ?spi chip select register? on page 670 ). when all bits are processed, the received data is transferred in the spi_rdr and the rdrf bit rises. if the spi_rdr has not been read before new data is received, the overrun e rror status (ovres) bit in the spi_sr is set. as long as this flag is set, data is loaded in the spi_rdr. the user must read spi_sr to clear the ovres bit. when a transfer starts, the data shifted out is the data present in the shift register. if no data has been written in the spi_tdr, the last data received is transferred. if no data has been received since the last reset, all bits are transmitted low, as the shift register resets to 0. when a first data is written in the spi_tdr, it is transferred immediately in the shift register and the tdre flag rises. if new data is written, it remains in the spi_tdr until a transfer occurs, i.e., nss falls and there is a valid clock on the spck pin. when the transfer occurs, the last data written in the spi_tdr is transferred in the shift register and the tdre flag rises. this enables frequent updates of critical variables with single transfers. then, new data is loaded in the shift register from the spi_tdr. if no character is ready to be transmitted, i.e., no character has been written in the spi_tdr since the last load from the spi_tdr to the shift register, the spi_tdr is retransmitted. in this case the underrun error status flag (undes) is set in the spi_sr. figure 33-12 shows a block diagram of the spi when operating in slave mode. figure 33-12. slave mode functional block diagram shift register spck spiens lsb msb nss mosi spi_rdr rd spi clock tdre spi_tdr td rdrf ovres spi_csr0 cpol ncpha bits spien spidis miso
659 sam4cp [datasheet] 43051e?atpl?08/14 33.7.5 register write protection to prevent any single software error f rom corrupting spi behavior, certain regi sters in the address space can be write- protected by setting the wpen bit in the ?spi write protection mode register? (spi_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the ?spi write protection status register? (spi_wpsr) is set and the wpvsrc field indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading spi_wpsr. the following registers can be write-protected: ? section 33.8.2 ?spi mode register? ? section 33.8.9 ?spi chip select register? 33.8 serial peripheral interface (spi) user interface table 33-5. register mapping offset register name access reset 0x00 control register spi_cr write-only ? 0x04 mode register spi_mr read/write 0x0 0x08 receive data register spi_rdr read-only 0x0 0x0c transmit data register spi_tdr write-only ? 0x10 status register spi_sr read-only 0x000000f0 0x14 interrupt enable register spi_ier write-only ? 0x18 interrupt disable register spi_idr write-only ? 0x1c interrupt mask register spi_imr read-only 0x0 0x20 - 0x2c reserved ? ? ? 0x30 chip select register 0 spi_csr0 read/write 0x0 0x34 chip select register 1 spi_csr1 read/write 0x0 0x38 chip select register 2 spi_csr2 read/write 0x0 0x3c chip select register 3 spi_csr3 read/write 0x0 0x40 - 0xe0 reserved ? ? ? 0xe4 write protection control register spi_wpmr read/write 0x0 0xe8 write protection status register spi_wpsr read-only 0x0 0x00ec - 0x00f8 reserved ? ? ? 0x00fc reserved ? ? ? 0x100 - 0x124 reserved for pdc registers ? ? ?
660 sam4cp [datasheet] 43051e?atpl?08/14 33.8.1 spi control register name: spi_cr address: 0x40008000 (0), 0x48000000 (1) access: write-only ? spien: spi enable 0 = no effect. 1 = enables the spi to transfer and receive data. ? spidis: spi disable 0 = no effect. 1 = disables the spi. as soon as spidis is set, spi finishes its transfer. all pins are set in input mode and no data is received or transmitted. if a transfer is in progress, the transfer is finished before the spi is disabled. if both spien and spidis are equal to one when the control register is written, the spi is disabled. ? swrst: spi software reset 0 = no effect. 1 = reset the spi. a software-triggered hardware reset of the spi interface is performed. the spi is in slave mode after software reset. pdc channels are not affected by software reset. ? lastxfer: last transfer 0 = no effect. 1 = the current npcs will be de-asserted after the character written in td has been transferred. when csaat is set, the commu- nication with the current serial peripheral can be closed by raising the corresponding npcs line as soon as td transfer is completed. refer to section 33.7.3.5 ?peripheral selection? for more details. 31 30 29 28 27 26 25 24 ??????? lastxfer 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 swrst ? ? ? ? ? spidis spien
661 sam4cp [datasheet] 43051e?atpl?08/14 33.8.2 spi mode register name: spi_mr address: 0x40008004 (0), 0x48000004 (1) access: read/write this register can only be written if the wpen bit is cleared in ?spi write protection mode register? . ? mstr: master/slave mode 0 = spi is in slave mode. 1 = spi is in master mode. ? ps: peripheral select 0 = fixed peripheral select. 1 = variable peripheral select. ? pcsdec: chip select decode 0 = the chip selects are directly connected to a peripheral device. 1 = the four chip select lines are connected to a 4- to 16-bit decoder. when pcsdec equals one, up to 15 chip select signals can be generated with the four lines using an external 4- to 16-bit decoder. the chip select registers define the characteristics of the 15 chip selects, with the following rules: spi_csr0 defines peripheral chip select signals 0 to 3. spi_csr1 defines peripheral chip select signals 4 to 7. spi_csr2 defines peripheral chip select signals 8 to 11. spi_csr3 defines peripheral chip select signals 12 to 14. ? modfdis: mode fault detection 0 = mode fault detection enabled. 1 = mode fault detection disabled. ? wdrbt: wait data read before transfer 0 = no effect. in master mode, a transfer can be initiated regardless of the spi_rdr state. 1 = in master mode, a transfer can start only if the spi_rdr is empty, i.e. does not contain any unread data. this mode prevent s overrun error in reception. 31 30 29 28 27 26 25 24 dlybcs 23 22 21 20 19 18 17 16 ???? pcs 15 14 13 12 11 10 9 8 ???????? 76543210 llb ? wdrbt modfdis ? pcsdec ps mstr
662 sam4cp [datasheet] 43051e?atpl?08/14 ? llb: local loopback enable 0 = local loopback path disabled. 1 = local loopback path enabled. llb controls the local loopback on the data shift register for testing in master mode only. (miso is internally connected on mo si). ? pcs: peripheral chip select this field is only used if fixed peripheral select is active (ps = 0). if pcsdec = 0: pcs = xxx0 npcs[3:0] = 1110 pcs = xx01 npcs[3:0] = 1101 pcs = x011 npcs[3:0] = 1011 pcs = 0111 npcs[3:0] = 0111 pcs = 1111 forbidden (no peripheral is selected) (x = don?t care) if pcsdec = 1: npcs[3:0] output signals = pcs. ? dlybcs: delay between chip selects this field defines the delay between the inactivation and the activation of npcs. the dlybcs time guarantees non-overlapping chip selects and solves bus contentions in case of peripherals having long data float times. if dlybcs is less than or equal to six, six peripheral clock periods are inserted by default. otherwise, the following equation determines the delay: delay between chip selects dlybcs 1 ? fperipheralclock ------------------------------------------------ =
663 sam4cp [datasheet] 43051e?atpl?08/14 33.8.3 spi receive data register name: spi_rdr address: 0x40008008 (0), 0x48000008 (1) access: read-only ? rd: receive data data received by the spi is stored in this register in a right-justified format. unused bits are read as zero. ? pcs: peripheral chip select in master mode only, these bits indicate the value on the npcs pins at the end of a transfer. otherwise, these bits read as zer o. note: when using variable peripheral select mode (ps = 1 in spi_mr) it is mandatory to set the spi_mr.wdrbt bit to 1 if the pcs field must be processed in spi_rdr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???? pcs 15 14 13 12 11 10 9 8 rd 76543210 rd
664 sam4cp [datasheet] 43051e?atpl?08/14 33.8.4 spi transmit data register name: spi_tdr address: 0x4000800c (0), 0x4800000c (1) access: write-only ? td: transmit data data to be transmitted by the spi interface is stored in this register. information to be transmitted must be written to the tr ansmit data register in a right-justified format. ? pcs: peripheral chip select this field is only used if variable peripheral select is active (ps = 1). if pcsdec = 0: pcs = xxx0 npcs[3:0] = 1110 pcs = xx01 npcs[3:0] = 1101 pcs = x011 npcs[3:0] = 1011 pcs = 0111 npcs[3:0] = 0111 pcs = 1111 forbidden (no peripheral is selected) (x = don?t care) if pcsdec = 1: npcs[3:0] output signals = pcs ? lastxfer: last transfer 0 = no effect. 1 = the current npcs will be deasserted after the character written in td has been transferred. when csaat is set, this allows to close the communication with the current se rial peripheral by raising the correspondi ng npcs line as soon as td transfer is completed. this field is only used if variable peripheral select is active (ps = 1). 31 30 29 28 27 26 25 24 ??????? lastxfer 23 22 21 20 19 18 17 16 ???? pcs 15 14 13 12 11 10 9 8 td 76543210 td
665 sam4cp [datasheet] 43051e?atpl?08/14 33.8.5 spi status register name: spi_sr address: 0x40008010 (0), 0x48000010 (1) access: read-only ? rdrf: receive data register full 0 = no data has been received since the last read of spi_rdr. 1 = data has been received and the received data has been transferred from the shift register to spi_rdr since the last read of spi_rdr. ? tdre: transmit data register empty 0 = data has been written to spi_tdr and not yet transferred to the shift register. 1 = the last data written in the transmit data register has been transferred to the shift register. tdre equals zero when the spi is disabled or at reset. the spi enable command sets this bit to 1. ? modf: mode fault error 0 = no mode fault has been detected since the last read of spi_sr. 1 = a mode fault occurred since the last read of the spi_sr. ? ovres: overrun error status 0 = no overrun has been detected since the last read of spi_sr. 1 = an overrun has occurred since the last read of spi_sr. an overrun occurs when spi_rdr is loaded at least twice from the shift register since the last read of the spi_rdr. ? endrx: end of rx buffer 0 = the receive counter register has not reached 0 since the last write in spi_rcr (1) or spi_rncr (1) . 1 = the receive counter register has reached 0 since the last write in spi_rcr (1) or spi_rncr (1) . ? endtx: end of tx buffer 0 = the transmit counter register has not reached 0 since the last write in spi_tcr (1) or spi_tncr (1) . 1 = the transmit counter register has reached 0 since the last write in spi_tcr (1) or spi_tncr (1) . ? rxbuff: rx buffer full 0 = spi_rcr (1) or spi_rncr (1) has a value other than 0. 1 = both spi_rcr (1) and spi_rncr (1) have a value of 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ??????? spiens 15 14 13 12 11 10 9 8 ? ? ? ? ? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
666 sam4cp [datasheet] 43051e?atpl?08/14 ? txbufe: tx buffer empty 0 = spi_tcr (1) or spi_tncr (1) has a value other than 0. 1 = both spi_tcr (1) and spi_tncr (1) have a value of 0. ? nssr: nss rising 0 = no rising edge detected on nss pin since last read. 1 = a rising edge occurred on nss pin since last read. ? txempty: transmission registers empty 0 = as soon as data is written in spi_tdr. 1 = spi_tdr and internal shifter are empty. if a transfer dela y has been defined, txempty is se t after the completion of such delay. ? undes: underrun error status (slave mode only) 0 = no underrun has been detected since the last read of spi_sr. 1 = a transfer begins whereas no data has been loaded in the transmit data register. ? spiens: spi enable status 0 = spi is disabled. 1 = spi is enabled. note: 1. spi_rcr, spi_rncr, spi_tcr, spi_tncr are physically located in the pdc.
667 sam4cp [datasheet] 43051e?atpl?08/14 33.8.6 spi interrupt enable register name: spi_ier address: 0x40008014 (0), 0x48000014 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0 = no effect. 1 = enables the corresponding interrupt. ? rdrf: receive data register full interrupt enable ? tdre: spi transmit data register empty interrupt enable ? modf: mode fault error interrupt enable ? ovres: overrun error interrupt enable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? rxbuff: receive buffer full interrupt enable ? txbufe: transmit buffer empty interrupt enable ? nssr: nss rising interrupt enable ? txempty: transmission registers empty enable ? undes: underrun error interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? ? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
668 sam4cp [datasheet] 43051e?atpl?08/14 33.8.7 spi interrupt disable register name: spi_idr address: 0x40008018 (0), 0x48000018 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0 = no effect. 1 = disables the corresponding interrupt. ? rdrf: receive data register full interrupt disable ? tdre: spi transmit data register empty interrupt disable ? modf: mode fault error interrupt disable ? ovres: overrun error interrupt disable ? endrx: end of receive buffer interrupt disable ? endtx: end of transmit buffer interrupt disable ? rxbuff: receive buffer full interrupt disable ? txbufe: transmit buffer empty interrupt disable ? nssr: nss rising interrupt disable ? txempty: transmission registers empty disable ? undes: underrun error interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? ? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
669 sam4cp [datasheet] 43051e?atpl?08/14 33.8.8 spi interrupt mask register name: spi_imr address: 0x4000801c (0), 0x4800001c (1) access: read-only the following configuration values are valid for all listed bit names of this register: 0 = the corresponding interrupt is not enabled. 1 = the corresponding interrupt is enabled. ? rdrf: receive data register full interrupt mask ? tdre: spi transmit data register empty interrupt mask ? modf: mode fault error interrupt mask ? ovres: overrun error interrupt mask ? endrx: end of receive buffer interrupt mask ? endtx: end of transmit buffer interrupt mask ? rxbuff: receive buffer full interrupt mask ? txbufe: transmit buffer empty interrupt mask ? nssr: nss rising interrupt mask ? txempty: transmission registers empty mask ? undes: underrun error interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? ? undes txempty nssr 76543210 txbufe rxbuff endtx endrx ovres modf tdre rdrf
670 sam4cp [datasheet] 43051e?atpl?08/14 33.8.9 spi chip select register name: spi_csrx[x=0..3] address: 0x40008030 (0), 0x40008034 (0), 0x40008038 (0), 0x4000803c (0), 0x48000030 (1), 0x40008034 (1), 0x40008038 (1), 0x4000803c (1) access: read/write this register can only be written if the wpen bit is cleared in ?spi write protection mode register? . note: 1. spi_csrx registers must be written even if the user wants to use the defaults. the bits field will not be updated with the translated value unless the register is written. ? cpol: clock polarity 0 = the inactive state value of spck is logic level zero. 1 = the inactive state value of spck is logic level one. cpol is used to determine the inactive state value of the serial clock (spck). it is used with ncpha to produce the required clock/data relationship between master and slave devices. ? ncpha: clock phase 0 = data is changed on the leading edge of spck and captured on the following edge of spck. 1 = data is captured on the leading edge of spck and changed on the following edge of spck. ncpha determines which edge of spck causes data to change and which edge causes data to be captured. ncpha is used with cpol to produce the required clock/data relationship between master and slave devices. ? csnaat: chip select not active after transfer (ignored if csaat = 1) 0 = the peripheral chip select does not rise between two transfers if the spi_tdr is reloaded before the end of the first trans fer and if the two transfers occur on the same chip select. 1 = the peripheral chip select rises systematically after each t ransfer performed on the same slave. it remains active after th e end of transfer for a minimal duration of: ? (if dlybct field is different from 0) ? (if dlybct field equals 0) 31 30 29 28 27 26 25 24 dlybct 23 22 21 20 19 18 17 16 dlybs 15 14 13 12 11 10 9 8 scbr 76543210 bits csaat csnaat ncpha cpol dlybct fperipheralclock ------------------------------------------------ dlybct 1 + fperipheralclock ------------------------------------------------
671 sam4cp [datasheet] 43051e?atpl?08/14 ? csaat: chip select active after transfer 0 = the peripheral chip select line rises as soon as the last transfer is achieved. 1 = the peripheral chip select does not rise after the last transfer is achieved. it remains active until a new transfer is req uested on a different chip select. ? bits: bits per transfer (see the note (1) below the register table; section 33.8.9 ?spi chip select register? on page 670 ). the bits field determines the number of data bits transferred. reserved values should not be used. ? scbr: serial clock baud rate in master mode, the spi interface uses a modulus counter to derive the spck baud ra te from the peripheral clock. the baud rate is selected by writing a value from 1 to 255 in the scbr field. the following equations determine the spck baud rate: do not program the scbr field to 0. triggering a transfer while scbr is at 0 can lead to unpredictable results. at reset, scbr is 0 and the user has to program it at a valid value before performing the first transfer. note: if one of the scbr fields inspi_csrx is set to 1, the other scbr fields in spi_csrx must be set to 1 as well, if they are required to process transfers. if they are not used to transfer data, they can be set at any value. ? dlybs: delay before spck this field defines the delay from npcs falling edge (activation) to the first valid spck transition. when dlybs equals zero, the delay is half the spck clock period. otherwise, the following equations determine the delay: value name description 0 8_bit 8 bits for transfer 1 9_bit 9 bits for transfer 2 10_bit 10 bits for transfer 3 11_bit 11 bits for transfer 4 12_bit 12 bits for transfer 5 13_bit 13 bits for transfer 6 14_bit 14 bits for transfer 7 15_bit 15 bits for transfer 8 16_bit 16 bits for transfer 9 ? reserved 10 ? reserved 11 ? reserved 12 ? reserved 13 ? reserved 14 ? reserved 15 ? reserved spck baud rate fperipheralclock scbr ------------------------------------------------ = delay before spck dlybs fperipheralclock ------------------------------------------------ =
672 sam4cp [datasheet] 43051e?atpl?08/14 ? dlybct: delay between consecutive transfers this field defines the delay between two consecutive transfers with the same peripheral without removing the chip select. the delay is always inserted after each transfer and before removing the chip select if needed. when dlybct equals zero, no delay between consecutive transfers is inserted and the clock keeps its duty cycle over the character transfers. otherwise, the following equation determines the delay: delay between consecutive transfers 32 dlybct ? fperipheralclock ------------------------------------------------ =
673 sam4cp [datasheet] 43051e?atpl?08/14 33.8.10 spi write protection mode register name: spi_wpmr address: 0x400080e4 (0), 0x480000e4 (1) access: read/write ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x535049 (?spi? in ascii). 1: enables the write protection if wpkey corresponds to 0x535049 (?spi? in ascii). see section 33.7.5 ?register write protection? for the list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x535049 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
674 sam4cp [datasheet] 43051e?atpl?08/14 33.8.11 spi write protection status register name: spi_wpsr address: 0x400080e8 (0), 0x480000e8 (1) access: read-only ? wpvs: write protection violation status 0 = no write protection violation has occurred since the last read of the spi_wpsr. 1 = a write protection violation has occurred since the last read of the spi_wpsr. if this violation is an unauthorized attempt to write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
675 sam4cp [datasheet] 43051e?atpl?08/14 34. two-wire interface (twi) 34.1 description the atmel two-wire interface (twi) interconnects components on a unique two-wire bus, made up of one clock line and one data line with speeds of up to 400 kbits per second, based on a byte-oriente d transfer format. it can be used with any atmel two-wire interface bus serial eeprom and i2c compatible device such as a real time clock (rtc), dot matrix/graphic lcd controllers and temperature sensor. the twi is programmable as a master or a slave with sequential or single-byte access. multiple master capability is supported. arbitration of the bus is performed internally and puts the twi in slave mode automatically if the bus arbitration is lost. a configurable baud rate generator permits the output data rate to be adapted to a wide range of core clock frequencies. table 34-1 lists the compatibility level of the atmel two-wire interface in master mode and a full i 2 c compatible device. note: 1. start + b000000001 + ack + sr 34.2 embedded characteristics ? compatible with atmel two-wire interface serial memory and i2c compatible devices (1) ? one, two or three bytes for slave address ? sequential read-write operations ? master, multi-master and slave mode operation ? bit rate: up to 400 kbit/s ? general call supported in slave mode ? smbus quick command supported in master mode ? connection to peripheral dma controller (pdc) channel capabilities optimizes data transfers ? one channel for the receiver, one channel for the transmitter ? register write protection note: 1. see table 34-1 for details on compatibility with i2c standard. table 34-1. atmel twi compatibility with i 2 c standard i 2 c standard atmel twi standard mode speed (100 khz) supported fast mode speed (400 khz) supported 7 or 10 bits slave addressing supported start byte (1) not supported repeated start (sr) condition supported ack and nack management supported slope control and input filtering (fast mode) not supported clock stretching/synchronization supported multi master capability supported
676 sam4cp [datasheet] 43051e?atpl?08/14 34.3 list of abbreviations 34.4 block diagram figure 34-1. block diagram 34.5 application block diagram figure 34-2. application block diagram table 34-2. abbreviations abbreviation description twi two-wire interface a acknowledge na non acknowledge p stop s start sr repeated start sadr slave address adr any address except sadr r read w write peripheral bridge pmc peripheral clock two-wire interface pio interrupt controller twi interrupt twck twd bus clock twd vdd host with twi interface twck atmel twi serial eeprom l 2c rtc l 2c lcd controller l 2c temp. sensor slave 1 slave 2 slave 3 slave 4 rp rp rp: pull up value as given by the l 2c standard
677 sam4cp [datasheet] 43051e?atpl?08/14 34.5.1 i/o lines description 34.6 product dependencies 34.6.1 i/o lines both twd and twck are bidirectional lines, connected to a positive supply voltage via a current source or pull-up resistor (see figure 34-2 ). when the bus is free, both lines are high. the output stages of devices connected to the bus must have an open-drain or open-collector to perform the wired-and function. twd and twck pins may be multiplexed with pio lines. to enable the twi, the user must program the pio controller to dedicate twd and twck as peripheral lines. the user must not program twd and twck as open-drain. it is already done by the hardware. 34.6.2 power management the twi interface may be clocked through the power management controller (pmc), thus the user must first configure the pmc to enable the twi clock. 34.6.3 interrupt the twi interface has an interrupt line connected to the int errupt controller. in order to handle interrupts, the interrupt controller must be programmed before configuring the twi. table 34-3. i/o lines description pin name pin description type twd two-wire serial data input/output twck two-wire serial clock input/output table 34-4. i/o lines instance signal i/o line peripheral twi0 twck0 pa25 a twi0 twd0 pa24 a twi1 twck1 pb1 a twi1 twd1 pb0 a table 34-5. peripheral ids instance id twi0 19 twi1 20
678 sam4cp [datasheet] 43051e?atpl?08/14 34.7 functional description 34.7.1 transfer format the data put on the twd line must be 8 bits long. data is transferred msb first; each byte must be followed by an acknowledgement. the number of bytes per transfer is unlimited (see figure 34-4 ). each transfer begins with a start condition and terminates with a stop condition (see figure 34-3 ). ? a high-to-low transition on the twd line while twck is high defines the start condition. ? a low-to-high transition on the twd line while twck is high defines the stop condition. figure 34-3. start and stop conditions figure 34-4. transfer format 34.7.2 modes of operation the twi has different modes of operations: ? master transmitter mode ? master receiver mode ? multi-master transmitter mode ? multi-master receiver mode ? slave transmitter mode ? slave receiver mode these modes are described in the following sections. twd twck start stop twd twck start address r/w ack data ack data ack stop
679 sam4cp [datasheet] 43051e?atpl?08/14 34.7.3 master mode 34.7.3.1 definition the master is the device that starts a transfer, generates a clock and stops it. 34.7.3.2 application block diagram figure 34-5. master mode typical application block diagram 34.7.3.3 programming master mode the following fields must to be programmed before entering master mode: 1. twi_mmr.dadr (+ iadrsz + iadr if a 10-bit device is addressed): the device address is used to access slave devices in read or write mode. 2. twi_cwgr.ckdiv + chdiv + cldiv: clock waveform. 3. twi_cr.svdis: disables the slave mode 4. twi_cr.msen: enables the master mode note: if the twi is already in master mode, the device address (dadr) can be configured without disabling the master mode. 34.7.3.4 master transmitter mode after the master initiates a start condi tion when writing into the transmit ho lding register (twi_thr), it sends a 7-bit slave address, configured in the master mode register (dadr in twi_mmr), to notify the slave device. the bit following the slave address indicates the transfer direction, 0 in this case (mread = 0 in twi_mmr). the twi transfers require the slave to acknowledge each received byte. during the acknowledge clock pulse (9th pulse), the master releases the data line (high), enabling the slave to pull it down in order to generate the acknowledge. the master polls the data line during this clock pulse and sets the not acknowledge bit (nack ) in the status register (twi_sr) if the slave does not acknowledge the byte. as with the other status bits, an interrupt can be generated if enabled in the interrupt enable register (twi_ier). if the slave acknowledges the byte, the data written in the twi_thr, is then shifted in the internal shifter and transferred. when an acknowledge is detected, the txrdy bit is set until a new write in the twi_thr. txrdy is used as transmit ready for the pdc transmit channel. while no new data is written in the twi_thr, the serial clock line is tied low. when new data is written in the twi_thr, the scl is released and the data is sent. setting the stop bit in twi_cr generates a stop condition. after a master write transfer, the serial clock line is stretched (tied low) as long as no new data is written in the twi_thr or until a stop command is performed. see figure 34-6 , figure 34-7 , and figure 34-8 . twd vdd host with twi interface twck atmel twi serial eeprom l 2c rtc l 2c lcd controller l 2c temp. sensor slave 1 slave 2 slave 3 slave 4 rp rp rp: pull up value as given by the l 2c standard
680 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-6. master write with one data byte figure 34-7. master write with multiple data bytes figure 34-8. master write with one byte internal address and multiple data bytes t xcomp txrdy write thr (data) stop co mm and sent (write in twi_cr) twd adataa s dadr w p a data n a s dadr w data n+1 a p data n+2 a t xcomp txrdy write thr (data n) write thr (data n+1) write thr (data n+2) last data sent stop command performed (by writing in the twi_cr) twd twck a data n a s dadr w data n+1 a p data n+2 a txcomp txrdy write thr (data n) write thr (data n+1) write thr (data n+2) last data sent stop command performed (by writing in the twi_cr) twd iadr a twck
681 sam4cp [datasheet] 43051e?atpl?08/14 34.7.3.5 master receiver mode the read sequence begins by setting the start bit. after the start condition has been sent, the master sends a 7-bit slave address to notify the slave device. the bit following the slave address indicates the transfer direction, 1 in this case (mread = 1 in twi_mmr). during the acknowledge clock pulse (9th pulse), the master releases the data line (high), enabling the slave to pull it down in order to generate the acknowledge. the master polls the data line during this clock pulse and sets the nack bit in the twi_sr if the slave does not acknowledge the byte. if an acknowledge is received, the master is then ready to receive data from the slave. after data has been received, the master sends an acknowledge condition to notify the slave that the data has been received except for the last data. see figure 34-9 . when the rxrdy bit is set in the twi_sr, a character has been received in the receive-holding register (twi_rhr). the rxrdy bit is reset when reading the twi_rhr. rxrdy is used as receive ready for the pdc receive channel. when a single data byte read is performed, with or without internal address (iadr), the start and stop bits must be set at the same time. see figure 34-9 . when a multiple data byte read is performed, with or without internal address (iadr), the stop bit must be set after the next-to-last data received. see figure 34-10 . for internal address usage see section 34.7.3.6 . if the receive holding register (twi_rhr) is full (rxrdy high) and the master is receiving data, the serial clock line will be tied low before receiving the last bit of the data and until the twi_rhr is read. once the twi_rhr is read, the master will stop stretching the serial clock line and end the data reception. see figure 34-11 . warning: when receiving multiple bytes in master read mode, if the next-to-last access is not read (the rxrdy flag remains high), the last access will not be completed until twi_rhr is read. the last access stops on the next-to-last bit. when the twi_rhr is read there is only half a bit period to send the stop bit command, else another read access might occur (spurious access). a possible workaround is to set the stop bit before reading the twi_rhr on the next-to-last access (within it handler). figure 34-9. master read with one data byte figure 34-10. master read with multiple data bytes a s dadr r data na p t xcomp write start & stop bit rxrdy read rhr twd na a s dadr r data n a a data (n+1) a data (n+m) data (n+m)-1 p twd t xcomp write start bit rxrdy write stop bit after next-to-last data read read rhr data n read rhr data (n+1) read rhr data (n+m)-1 read rh r data (n+m )
682 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-11. master read wait state with multiple data bytes 34.7.3.6 internal address the twi interface can perform transfers with 7-bit slave address devices and 10-bit slave address devices. 7-bit slave addressing when addressing 7-bit slave devices, the internal address bytes are used to perform random address (read or write) accesses to reach one or more data bytes, e.g. within a memory page location in a serial memory. when performing read operations with an internal address, the twi performs a write operation to set the internal address into the slave device, and then switch to master receiver mode. note that the second start condition (after sending the iadr) is sometimes called ?repeated start? (sr) in i 2 c fully-compatible devices. see figure 34-13 . see figure 34-12 and figure 34-14 for master write operation with internal address. the three internal address bytes are configurable through the master mode register (twi_mmr). if the slave device supports only a 7-bit address, i.e., no internal address, iadrsz must be set to 0. table 34-6 shows the abbreviations used in figure 34-12 and figure 34-13 . adata na s dadr w data n+1 a p data n+2 a txcomp rxrdy read rhr (data n) stop command performed (by writing in the twi_cr) twd twck read rhr (data n+1) read rhr (data n+2) clock wait state table 34-6. abbreviations abbreviation definition s start sr repeated start p stop w write r read a acknowledge na not acknowledge dadr device address iadr internal address
683 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-12. master write with one, two or three bytes internal address and one data byte figure 34-13. master read with one, two or three bytes internal address and one data byte 10-bit slave addressing for a slave address higher than 7 bits, the user must configure the address size ( iadrsz) and set the other slave address bits in the internal address register (twi_iadr). the two remaining internal address bytes, iadr[15:8] and iadr[23:16] can be used the same way as in 7-bit slave addressing. example: address a 10-bit device (10-bit device address is b1 b2 b3 b4 b5 b6 b7 b8 b9 b10) 1. program iadrsz = 1. 2. program dadr with 1 1 1 1 0 b1 b2 (b1 is the msb of the 10-bit address, b2, etc). 3. program twi_iadr with b3 b4 b5 b6 b7 b8 b9 b10 (b10 is the lsb of the 10-bit address). figure 34-14 below shows a byte write to an atmel at24lc512 eeprom. this demonstrates the use of internal addresses to access the device. figure 34-14. internal address usage 34.7.3.7 using the peripheral dma controller (pdc) the use of the pdc significantly reduces the cpu load. to assure correct implementation, respect the following programming sequences: data transmit with the pdc 1. initialize the transmit pdc (memory pointers, transfer size - 1). 2. configure the master (dadr, ckdiv, mread = 0, etc.). s dadr w a iadr(23:16) a iadr(15:8) a iadr(7:0) a data a p s dadr w a iadr(15:8) a iadr(7:0) a p data a a iadr(7:0) a p data a s dadr w twd three bytes internal address two bytes internal address one byte internal address twd twd s dadr w a iadr(23:16) a iadr(15:8) a iadr(7:0) a s dadr w a iadr(15:8) a iadr(7:0) a a iadr(7:0) a s dadr w data n a p sr dadr r a sr dadr r a data na p sr dadr r a data n a p t wd t wd t wd three bytes internal address two bytes internal address one byte internal address s t a r t m s b device address 0 l s b r / w a c k m s b w r i t e a c k a c k l s b a c k first word address second word address data s t o p
684 sam4cp [datasheet] 43051e?atpl?08/14 3. start the transfer by setting the pdc txten bit. 4. wait for the pdc endtx flag either by using the polling method or endtx interrupt. 5. disable the pdc by setting the pdc txtdis bit. 6. wait for the txrdy flag in twi_sr. 7. set the stop bit in twi_cr. 8. write the last character in twi_thr. 9. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. data receive with the pdc the pdc transfer size must be defined with the buffer size minus 2. the two remaining characters must be managed without pdc to ensure that the exact number of bytes are received regardless of system bus latency conditions encountered during the end of buffer transfer period. in slave mode, the number of characters to receive must be known in order to configure the pdc. 1. initialize the receive pdc (memory pointers, transfer size - 2). 2. configure the master (dadr, ckdiv, mread = 1, etc.). 3. set the pdc rxten bit. 4. (master only) write the start bit in the twi_cr to start the transfer. 5. wait for the pdc endrx flag either by using polling method or endrx interrupt. 6. disable the pdc by setting the pdc rxtdis bit. 7. wait for the rxrdy flag in twi_sr. 8. set the stop bit in twi_cr. 9. read the penultimate character in twi_rhr. 10. wait for the rxrdy flag in twi_sr. 11. read the last character in twi_rhr. 12. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. 34.7.3.8 smbus quick command (master mode only) the twi interface can perform a quick command: 1. configure the master mode (dadr, ckdiv, etc). 2. write the mread bit in the twi_mmr at the value of the one-bit command to be sent. 3. start the transfer by setting the quick bit in the twi_cr. figure 34-15. smbus quick command txcomp txrdy write quick command in twi_cr twd a s dadr r/w p
685 sam4cp [datasheet] 43051e?atpl?08/14 34.7.3.9 read/write flowcharts the following flowcharts shown in figure 34-17 on page 686 , figure 34-18 on page 687 , figure 34-19 on page 688 , figure 34-20 on page 689 and figure 34-21 on page 690 give examples for read and write operations. a polling or interrupt method can be used to check the status bits. the interrupt method requires that the interrupt enable register (twi_ier) be configured first. figure 34-16. twi write operation with single data byte without internal address set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address (dadr) - transfer direction bit write ==> bit mread = 0 load transmit register twi_thr = data to send read status register txrdy = 1? read status register txcomp = 1? transfer finished ye s ye s begin no no write stop command twi_cr = stop
686 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-17. twi write operation with single data byte and internal address begin set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address (dadr) - internal address size (iadrsz) - transfer direction bit write ==> bit mread = 0 load transmit register twi_thr = data to send read status register txrdy = 1? read status register txcomp = 1? transfer finished set the internal address twi_iadr = address yes yes no no write stop command twi_cr = stop
687 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-18. twi write operation with multiple data bytes with or without internal address set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - internal address size (if iadr used) - transfer direction bit write ==> bit mread = 0 internal address size = 0? load transmit register twi_thr = data to send read status register txrdy = 1? data to send? read status register txcomp = 1? end begin set the internal address twi_iadr = address ye s twi_thr = data to send ye s ye s ye s no no no write stop command twi_cr = stop no set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once)
688 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-19. twi read operation with single data byte without internal address begin set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - transfer direction bit read ==> bit mread = 1 start the transfer twi_cr = start | stop read status register no no rxrdy = 1? read receive holding register yes yes read status register txcomp = 1? end
689 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-20. twi read operation with single data byte and internal address set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - internal address size (iadrsz) - transfer direction bit read ==> bit mread = 1 read status register txcomp = 1? end begin ye s set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) ye s set the internal address twi_iadr = address start the transfer twi_cr = start | stop read status register rxrdy = 1? read receive holding register no no
690 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-21. twi read operation with multiple data bytes with or without internal address internal address size = 0? start the transfer twi_cr = start stop the transfer twi_cr = stop read status register rxrdy = 1? last data to read but one? read status register txcomp = 1? end set the internal address twi_iadr = address ye s ye s ye s no ye s read receive holding register (twi_rhr) no set the control register: - master enable twi_cr = msen + svdis set the master mode register: - device slave address - internal address size (if iadr used) - transfer direction bit read ==> bit mread = 1 begin set twi clock (cldiv, chdiv, ckdiv) in twi_cwgr (needed only once) no no read status register rxrdy = 1? ye s read receive holding register (twi_rhr) no
691 sam4cp [datasheet] 43051e?atpl?08/14 34.7.4 multi-master mode 34.7.4.1 definition in multi-master mode, more than one master may handle the bus at the same time without data corruption by using arbitration. arbitration starts as soon as two or more masters place information on the bus at the same time, and stops (arbitration is lost) for the master that intends to send a logical one while the other master sends a logical zero. as soon as arbitration is lost by a master, it stops sending data and listens to the bus in order to detect a stop. when the stop is detected, the master that has lost arbitration may put its data on the bus by respecting arbitration. arbitration is illustrated in figure 34-23 on page 692 . 34.7.4.2 different multi-master modes two multi-master modes may be distinguished: 1. twi is considered as a master only and will never be addressed. 2. twi may be either a master or a slave and may be addressed. note: arbitration is supported in both multi-master modes. twi as master only in this mode, twi is considered as a master only (msen is always at one) and must be driven like a master with the arblst (arbitration lost) flag in addition. if arbitration is lost (arblst = 1), the user must reinitiate the data transfer. if the user starts a transfer (ex.: dadr + start + w + write in thr) and if the bus is busy, the twi automatically waits for a stop condition on the bus to initiate the transfer (see figure 34-22 on page 692 ). note: the state of the bus (busy or free) is not indicated in the user interface. twi as master or slave the automatic reversal from master to slave is not supported in case of a lost arbitration. then, in the case where twi may be either a master or a slave, the user must manage the pseudo multi-master mode described in the steps below. 1. program twi in slave mode (sadr + msdis + sven) and perform a slave access (if twi is addressed). 2. if the twi has to be set in master mode, wait until txcomp flag is at 1. 3. program the master mode (dadr + svdis + msen) and start the transfer (ex: start + write in thr). 4. as soon as the master mode is enabled, twi scans the bus in order to detect if it is busy or free. when the bus is considered free, twi initiates the transfer. 5. as soon as the transfer is initiated and until a stop condition is sent, the arbitration becomes relevant and the user must monitor the arblst flag. 6. if the arbitration is lost (arblst is set to 1), the user must program the twi in slave mode in case the master that won the arbitration wants to access the twi. 7. if the twi has to be set in slave mode, wait until txcomp flag is at 1 and then program the slave mode. note: if the arbitration is lost and the twi is addressed, the twi will not acknowledge even if it is programmed in slave mode as soon as arblst is set to 1. then, the master must repeat sadr.
692 sam4cp [datasheet] 43051e?atpl?08/14 figure 34-22. programmer sends data while the bus is busy figure 34-23. arbitration cases twck twd data sent by a master stop sent by the master start sent by the twi data sent by the twi bus is busy bus is free a transfer is programmed (dadr + w + start + write thr) transfer is initiated twi data transfer transfer is kept bus is considered as free twck bus is busy bus is free a transfer is programmed (dadr + w + start + write thr) transfer is initiated twi data transfer transfer is kept bus is considered as free data from a master data from twi s 0 s 0 0 1 1 1 arblst s 0 s 0 0 1 1 1 twd s 0 0 1 1 1 1 1 arbitration is lost twi stops sending data p s 0 1 p 0 1 1 1 1 data from the master data from the twi arbitration is lost the master stops sending data transfer is stopped transfer is programmed again (dadr + w + start + write thr) twck twd
693 sam4cp [datasheet] 43051e?atpl?08/14 the flowchart shown in figure 34-24 on page 693 gives an example of read and write operations in multi-master mode. figure 34-24. multi-master flowchart program the slave mode: sadr + msdis + sven svacc = 1 ? txcomp = 1 ? gacc = 1 ? decoding of the programming sequence prog seq ok ? change sadr svread = 1 ? read status register rxrdy= 1 ? read twi_rhr txrdy= 1 ? eosacc = 1 ? write in twi_thr need to perform a master access ? program the master mode dadr + svdis + msen + clk + r / w read status register arblst = 1 ? mread = 1 ? txrdy= 0 ? write in twi_thr data to send ? rxrdy= 0 ? read twi_rhr data to read? read status register txcomp = 0 ? general call treatment yes yes yes yes yes yes yes yes yes yes yes yes yes yes stop transfer twi_cr = stop no no no no no no no no no no no no no no no no start
694 sam4cp [datasheet] 43051e?atpl?08/14 34.7.5 slave mode 34.7.5.1 definition slave mode is defined as a mode where the device receives the clock and the address from another device called the master. in this mode, the device never initiates and never completes the transmission (start, repeated start and stop conditions are always provided by the master). 34.7.5.2 application block diagram figure 34-25. slave mode typical application block diagram 34.7.5.3 programming slave mode the following fields must be programmed before entering slave mode: 1. twi_smr.sadr: the slave device address is used in order to be accessed by master devices in read or write mode. 2. twi_cr.msdis: disables the master mode. 3. twi_cr.sven: enables the slave mode. as the device receives the clock, values written in twi_cwgr are ignored. 34.7.5.4 receiving data after a start or repeated start condition is detected and if the address sent by the master matches with the slave address programmed in the sadr (slave address) field, svacc (slave access) flag is set and svread (slave read) indicates the direction of the transfer. svacc remains high until a stop condition or a repeated st art is detected. when such a condition is detected, the eosacc (end of slave access) flag is set. read sequence in the case of a read sequence (svread is high), twi tran sfers data written in the twi_thr (twi transmit holding register) until a stop condition or a repeated start + an address different from sadr is detected. note that at the end of the read sequence txcomp (transmission complete) flag is set and svacc reset. as soon as data is written in the twi_thr, the txrdy (transmit holding register ready) flag is reset, and it is set when the internal shifter is empty and the sent data acknowledged or not. if the data is not acknowledged, the nack flag is set. note that a stop or a repeated start always follows a nack. see figure 34-26 on page 695 . write sequence in the case of a write sequence (svread is low), the rxrdy (receive holding register ready) flag is set as soon as a character has been received in the twi_rhr (twi receive holding register). rxrdy is reset when reading the twi_rhr. rr vdd twd host with twi interface twck lcd controller slave 1 slave 2 slave 3 host with twi interface host with twi interface master
695 sam4cp [datasheet] 43051e?atpl?08/14 twi continues receiving data until a stop condition or a repeated start + an address different from sadr is detected. note that at the end of the write sequence txcomp flag is set and svacc reset. see figure 34-27 on page 696 . clock synchronization sequence in twi_rhr is not read in time, thetwi performs a clock synchronization. clock synchronization information is given by the bit sclws (clock wait state). see figure 34-30 on page 698 . clock stretching sequence in twi_thr is not written in time, the twi performs a clock stretching. clock stretching information is given by the bit sclws (clock wait state). see figure 34-29 on page 697 . general call in the case where a general call is performed, the gacc (general call access) flag is set. after gacc is set, the user must interpret the meaning of the general call and decode the new address programming sequence. see figure 34-28 on page 696 . 34.7.5.5 data transfer read operation the read mode is defined as a data requirement from the master. after a start or a repeated start c ondition is detected, the decoding of the address starts. if the slave address (sadr) is decoded, svacc is set and svread indicates the direction of the transfer. until a stop or repeated start condition is detected, twi continues sending data loaded in the twi_thr. if a stop condition or a repeated start + an address different from sadr is detected, svacc is reset. figure 34-26 describes the write operation. figure 34-26. read access ordered by a master notes: 1. when svacc is low, the state of svread becomes irrelevant. 2. txrdy is reset when data has been transmitted from twi_thr to the internal shifter and set when this data has been acknowledged or non acknowledged. write thr read rhr svread has to be taken into account only while svacc is activ e twd txrdy nack svacc svread eosvacc sadr s adr r na r a data a a data na s/sr data na p/s/sr sadr matches, twi answers with an ack sadr does not match, twi answers with a nack ack/nack from the master
696 sam4cp [datasheet] 43051e?atpl?08/14 write operation the write mode is defined as a data transmission from the master. after a start or a repeated start, the decoding of the address starts. if the slave address is decoded, svacc is set and svread indicates the direction of the transfer (svread is low in this case). until a stop or repeated start condition is detected, twi stores the received data in the twi_rhr. if a stop condition or a repeated start + an address different from sadr is detected, svacc is reset. figure 34-27 describes the write operation. figure 34-27. write access ordered by a master notes: 1. when svacc is low, the state of svread becomes irrelevant. 2. rxrdy is set when data has been transmitted from the internal shifter to the twi_rhr and reset when this data is read. general call the general call is performed in order to change the address of the slave. if a general call is detected, gacc is set. after the detection of general call, it is up to the programmer to decode the commands which come afterwards. in case of a write command, the programmer has to decode the programming sequence and program a new sadr if the programming sequence matches. figure 34-28 describes the general call access. figure 34-28. master performs a general call note: this method allows the user to create a personal programming sequence by choosing the programming bytes and the number of them. the programming sequence has to be provided to the master. rxrdy read rhr svread has to be taken into account only while svacc is activ e twd svacc svread eosvacc sadr does not match, twi answers with a nack sadr s adr w na w a data a a data na s/sr data na p/s/sr sadr matches, twi answers with an ack 0000000 + w general call p s a general call reset or write dadd a new sadr data1 adata2 a a new sadr programming sequence txd gcacc svacc reset command = 00000110x write command = 00000100x reset after read
697 sam4cp [datasheet] 43051e?atpl?08/14 clock synchronization/stretching in both read and write modes, it may occur that twi_thr/twi_rhr buffer is not filled/emptied before the emission/reception of a new character. in this case, to avoid sending/receiving undesired data, clock stretching/synchronization mechanism is implemented. clock stretching in read mode the clock is tied low during the acknowledge phase if the internal shifter is empty and if a stop or repeated start condition was not detected. it is tied low until the internal shifter is loaded. figure 34-29 describes the clock stretching in read mode. figure 34-29. clock stretching in read mode notes: 1. txrdy is reset when data has been written in the twi_thr to the internal shifter and set when this data has been acknowledged or non acknowledged. 2. at the end of the read sequence, txcomp is set after a stop or after a repeated start + an address different from sadr. 3. sclws is automatically set when the clock stretching mechanism is started. data 1 the clock is stretched after the ack, the state of twd is undefined during clock stretching sclws svacc svread txrdy twck twi_thr txcomp the data is memorized in twi_thr until a new value is written twi_thr is transmitted to the shift register ack or nack from the master data 0 data 0 data 2 1 2 1 clock is tied low by the twi as long as thr is empty s sadr s r data 0 a a data 1 a data 2 na s xxxxxxx 2 write thr as soon as a start is detected
698 sam4cp [datasheet] 43051e?atpl?08/14 clock synchronization in write mode the clock is tied low outside of the acknowledge phase if the internal shifter and the twi_rhr is full. if a stop or repeated start condition was not detected, it is tied low until twi_rhr is read. figure 34-30 describes the clock synchronization in write mode. figure 34-30. clock synchronization in write mode notes: 1. at the end of the read sequence, txcomp is set after a stop or after a repeated start + an address different from sadr. 2. sclws is automatically set when the clock synchronization mechanism is started and automatically reset when the mechanism is finished. reversal after a repeated start reversal of read to write the master initiates the communication by a read command and finishes it by a write command. figure 34-31 describes the repeated start + reversal from read to write mode. figure 34-31. repeated start + reversal from read to write mode notes: 1. txcomp is only set at the end of the transmission because after the repeated start, sadr is detected again. rd data0 rd data1 rd data2 svacc svread rxrdy sclws txcomp data 1 data 2 scl is stretched on the last bit of data1 as soon as a start is detected twck twd twi_rhr clock is tied low by the twi as long as rhr is full data0 is not read in the rhr adr s sadr w a data 0 a a data 2 data 1 s na s sadr r a data 0 a data 1 sadr sr na w a data 2 a data 3 a p cleared after read data 0 data 1 data 2 data 3 svacc svread twd twi_thr twi_rhr eosacc txrdy rxrdy txcomp as soon as a start is detected
699 sam4cp [datasheet] 43051e?atpl?08/14 reversal of write to read the master initiates the communication by a write command and finishes it by a read command. figure 34-32 describes the repeated start + reversal from write to read mode. figure 34-32. repeated start + reversal from write to read mode notes: 1. in this case, if twi_thr has not been written at the end of the read command, the clock is automatically stretched before the ack. 2. txcomp is only set at the end of the transmission because after the repeated start, sadr is detected again. 34.7.5.6 using the peripheral dma controller (pdc) in slave mode the use of the pdc significantly reduces the cpu load. data transmit with the pdc in slave mode the following procedure shows an example to transmit data with pdc. 1. initialize the transmit pdc (memory pointers, transfer size). 2. start the transfer by setting the pdc txten bit. 3. wait for the pdc endtx flag either by using the polling method or endtx interrupt. 4. disable the pdc by setting the pdc txtdis bit. 5. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. data receive with the pdc in slave mode the following procedure shows an example to transmit data with pdc where the number of characters to receive is known. 1. initialize the receive pdc (memory pointers, transfer size). 2. set the pdc rxten bit. 3. wait for the pdc endrx flag either by using polling method or endrx interrupt. 4. disable the pdc by setting the pdc rxtdis bit. 5. (optional) wait for the txcomp flag in twi_sr before disabling the peripheral clock if required. s sadr w a data 0 a data 1 sadr sr a r a data 2 a data 3 n a p cleared after read data 0 data 2 data 3 data 1 txcomp txrdy rxrdy as soon as a start is detected read twi_rhr svacc svread twd twi_rhr twi_thr eosacc
700 sam4cp [datasheet] 43051e?atpl?08/14 34.7.5.7 read write flowcharts the flowchart shown in figure 34-33 gives an example of read and write operations in slave mode. a polling or interrupt method can be used to check the status bits. the interrupt method requires that the interrupt enable register (twi_ier) be configured first. figure 34-33. read write flowchart in slave mode 34.7.6 register write protection to prevent any single software error from corrupting twi behavior, certain registers in the address space can be write- protected by setting the wpen bit in the ?twi write protection mode register? (twi_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the ?twi write protection status register? (twi_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the twi_wpsr. the following registers can be write-protected: ? ?twi slave mode register? . ? ?twi clock waveform generator register? set the slave mode: sadr + msdis + sven svacc = 1 ? txcomp = 1 ? gacc = 1 ? decoding of the programming sequence prog seq ok ? change sadr svread = 0 ? read status register rxrdy= 0 ? read twi_rhr txrdy= 1 ? eosacc = 1 ? write in twi_thr end general call treatment no no no no no no no no
701 sam4cp [datasheet] 43051e?atpl?08/14 34.8 two-wire interface (twi) user interface note: all unlisted offset values are considered as ?reserved?. table 34-7. register mapping offset register name access reset 0x00 control register twi_cr write-only - 0x04 master mode register twi_mmr read/write 0x00000000 0x08 slave mode register twi_smr read/write 0x00000000 0x0c internal address register twi_iadr read/write 0x00000000 0x10 clock waveform generator register twi_cwgr read/write 0x00000000 0x14 - 0x1c reserved ? ? ? 0x20 status register twi_sr read-only 0x0000f009 0x24 interrupt enable register twi_ier write-only - 0x28 interrupt disable register twi_idr write-only - 0x2c interrupt mask register twi_imr read-only 0x00000000 0x30 receive holding register twi_rhr read-only 0x00000000 0x34 transmit holding register twi_thr write-only ? 0x38 - 0xe0 reserved ? ? ? 0xe4 write protection mode register twi_wpmr read/write 0x00000000 0xe8 write protection status register twi_wpsr read-only 0x00000000 0xec - 0xfc reserved ? ? ? 0x100 - 0x128 reserved for pdc registers ? ? ?
702 sam4cp [datasheet] 43051e?atpl?08/14 34.8.1 twi control register name: twi_cr address: 0x40018000 (0), 0x4001c000 (1) access: write-only ? start: send a start condition 0 = no effect. 1 = a frame beginning with a start bit is transmitted according to the features defined in the mode register. this action is necessary when the twi peripheral wants to read data from a slave. when configured in master mode with a write operation, a frame is sent as soon as the user writes a character in the transmit holding register (twi_thr). ? stop: send a stop condition 0 = no effect. 1 = stop condition is sent just after completing the current byte transmission in master read mode. ? in single data byte master read, the start and stop must both be set. ? in multiple data bytes master read, the stop must be set after the last data received but one. ? in master read mode, if a nack bit is received, the stop is automatically performed. ? in master data write operation, a stop condition will be sent after the transmission of the current data is finished. ? msen: twi master mode enabled 0 = no effect. 1 = enables the master mode (msdis must be written to 0). note: switching from slave to master mode is only permitted when txcomp = 1. ? msdis: twi master mode disabled 0 = no effect. 1 = the master mode is disabled, all pending data is transmitted . the shifter and holding characters (if it contains data) are transmitted in case of write operation. in read operation, the character being transferred must be completely received before disabling. ? sven: twi slave mode enabled 0 = no effect. 1 = enables the slave mode (svdis must be written to 0). note: switching from master to slave mode is only permitted when txcomp = 1. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 swrst quick svdis sven msdis msen stop start
703 sam4cp [datasheet] 43051e?atpl?08/14 ? svdis: twi slave mode disabled 0 = no effect. 1 = the slave mode is disabled. the shifter and holding characters (if it contains data) are transmitted in case of read operat ion. in write operation, the character being transferred must be completely received before disabling. ? quick: smbus quick command 0 = no effect. 1 = if master mode is enabled, a smbus quick command is sent. ? swrst: software reset 0 = no effect. 1 = equivalent to a system reset.
704 sam4cp [datasheet] 43051e?atpl?08/14 34.8.2 twi master mode register name: twi_mmr address: 0x40018004 (0), 0x4001c004 (1) access: read/write ? iadrsz: internal device address size ? mread: master read direction 0 = master write direction. 1 = master read direction. ? dadr: device address the device address is used to access slave devices in read or write mode. these bits are only used in master mode. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? dadr 15 14 13 12 11 10 9 8 ? ? ? mread ? ? iadrsz 76543210 ???????? value name description 0 none no internal device address 1 1_byte one-byte internal device address 2 2_byte two-byte internal device address 3 3_byte three-byte internal device address
705 sam4cp [datasheet] 43051e?atpl?08/14 34.8.3 twi slave mode register name: twi_smr address: 0x40018008 (0), 0x4001c008 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?twi write protection mode register? . ? sadr: slave address the slave device address is used in slave mode in order to be accessed by master devices in read or write mode. sadr must be programmed before enabling the slave mode or after a general call. writes at other times have no effect. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? sadr 15 14 13 12 11 10 9 8 ???????? 76543210 ????????
706 sam4cp [datasheet] 43051e?atpl?08/14 34.8.4 twi internal address register name: twi_iadr address: 0x4001800c (0), 0x4001c00c (1) access: read/write ? iadr: internal address 0, 1, 2 or 3 bytes depending on iadrsz. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 iadr 15 14 13 12 11 10 9 8 iadr 76543210 iadr
707 sam4cp [datasheet] 43051e?atpl?08/14 34.8.5 twi clock waveform generator register name: twi_cwgr address: 0x40018010 (0), 0x4001c010 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?twi write protection mode register? . twi_cwgr is only used in master mode. ? cldiv: clock low divider the scl low period is defined as follows: ? chdiv: clock high divider the scl high period is defined as follows: ? ckdiv: clock divider the ckdiv is used to increase both scl high and low periods. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ? ckdiv 15 14 13 12 11 10 9 8 chdiv 76543210 cldiv t low cldiv 2 ckdiv ? ?? 4 + t peripheralclock ? = t high chdiv 2 ckdiv ? ?? 4 + t peripheralclock ? =
708 sam4cp [datasheet] 43051e?atpl?08/14 34.8.6 twi status register name: twi_sr address: 0x40018020 (0), 0x4001c020 (1) access: read-only ? txcomp: transmission completed (automatically set / reset) txcomp used in master mode: 0 = during the length of the current frame. 1 = when both holding register and internal shifter are empty and stop condition has been sent. txcomp behavior in master mode can be seen in figure 34-8 on page 680 and in figure 34-10 on page 681 . txcomp used in slave mode: 0 = as soon as a start is detected. 1 = after a stop or a repeated start + an address different from sadr is detected. txcomp behavior in slave mode can be seen in figure 34-29 on page 697 , figure 34-30 on page 698 , figure 34-31 on page 698 and figure 34-32 on page 699 . ? rxrdy: receive holding register ready (automatically set / reset) 0 = no character has been received since the last twi_rhr read operation. 1 = a byte has been received in the twi_rhr since the last read. rxrdy behavior in master mode can be seen in figure 34-10 on page 681 . rxrdy behavior in slave mode can be seen in figure 34-27 on page 696 , figure 34-30 on page 698 , figure 34-31 on page 698 and figure 34-32 on page 699 . ? txrdy: transmit holding register ready (automatically set / reset) txrdy used in master mode: 0 = the transmit holding register has not been transferred into internal shifter. set to 0 when writing into twi_thr. 1 = as soon as a data byte is transferred from twi_thr to internal shifter or if a nack error is detected, txrdy is set at the same time as txcomp and nack. txrdy is also set when msen is set (enable twi). txrdy behavior in master mode can be seen in figure 34.7.3.4 on page 679 . txrdy used in slave mode: 0 = as soon as data is written in the twi_thr, until this data has been transmitted and acknowledged (ack or nack). 1 = it indicates that the twi_thr is empty and that data has been transmitted and acknowledged. if txrdy is high and if a nack has been detected, the transmission will be stopped. thus when trdy = nack = 1, the programmer must not fill twi_thr to avoid losing it. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc sclws arblst nack 76543210 ? ovre gacc svacc svread txrdy rxrdy txcomp
709 sam4cp [datasheet] 43051e?atpl?08/14 txrdy behavior in slave mode can be seen in figure 34-26 on page 695 , figure 34-29 on page 697 , figure 34-31 on page 698 and figure 34-32 on page 699 . ? svread: slave read (automatically set / reset) this bit is only used in slave mode. when svacc is low (no slave access has been detected) svread is irrelevant. 0 = indicates that a write access is performed by a master. 1 = indicates that a read access is performed by a master. svread behavior can be seen in figure 34-26 on page 695 , figure 34-27 on page 696 , figure 34-31 on page 698 and figure 34-32 on page 699 . ? svacc: slave access (automatically set / reset) this bit is only used in slave mode. 0 = twi is not addressed. svacc is automatically cleared after a nack or a stop condition is detected. 1 = indicates that the address decoding sequence has matched (a master has sent sadr). svacc remains high until a nack or a stop condition is detected. svacc behavior can be seen in figure 34-26 on page 695 , figure 34-27 on page 696 , figure 34-31 on page 698 and figure 34-32 on page 699 . ? gacc: general call access (clear on read) this bit is only used in slave mode. 0 = no general call has been detected. 1 = a general call has been detected. after the detection of general call, if need be, the programmer may acknowledge this access and decode the following bytes and respond according to the value of the bytes. gacc behavior can be seen in figure 34-28 on page 696 . ? ovre: overrun error (clear on read) this bit is only used in master mode. 0 = twi_rhr has not been loaded while rxrdy was set. 1 = twi_rhr has been loaded while rxrdy was set. reset by read in twi_sr when txcomp is set. ? nack: not acknowledged (clear on read) nack used in master mode: 0 = each data byte has been correctly received by the far-end side twi slave component. 1 = a data byte or an address byte has not been acknowledged by the slave component. set at the same time as txcomp. nack used in slave read mode: 0 = each data byte has been correctly received by the master. 1 = in read mode, a data byte has not been acknowledged by the master. when nack is set the programmer must not fill twi_thr even if txrdy is set, because it means that the master will stop the data transfer or re initiate it. note that in slave write mode all data are acknowledged by the twi. ? arblst: arbitration lost (clear on read) this bit is only used in master mode. 0: arbitration won. 1: arbitration lost. another master of the twi bus has won the multi-master arbitration. txcomp is set at the same time.
710 sam4cp [datasheet] 43051e?atpl?08/14 ? sclws: clock wait state (automatically set / reset) this bit is only used in slave mode. 0 = the clock is not stretched. 1 = the clock is stretched. twi_thr / twi_rhr buffer is not filled / emptied before the emission / reception of a new character . sclws behavior can be seen in figure 34-29 on page 697 and figure 34-30 on page 698 . ? eosacc: end of slave access (clear on read) this bit is only used in slave mode. 0 = a slave access is being performing. 1 = the slave access is finished. end of slave access is automatically set as soon as svacc is reset. eosacc behavior can be seen in figure 34-31 on page 698 and figure 34-32 on page 699 . ? endrx: end of rx buffer 0 = the receive counter register has not reached 0 since the last write in twi_rcr or twi_rncr. 1 = the receive counter register has reached 0 since the last write in twi_rcr or twi_rncr. ? endtx: end of tx buffer 0 = the transmit counter register has not reached 0 since the last write in twi_tcr or twi_tncr. 1 = the transmit counter register has reached 0 since the last write in twi_tcr or twi_tncr. ? rxbuff: rx buffer full 0 = twi_rcr or twi_rncr have a value other than 0. 1 = both twi_rcr and twi_rncr have a value of 0. ? txbufe: tx buffer empty 0 = twi_tcr or twi_tncr have a value other than 0. 1 = both twi_tcr and twi_tncr have a value of 0.
711 sam4cp [datasheet] 43051e?atpl?08/14 34.8.7 twi interrupt enable register name: twi_ier address: 0x40018024 (0), 0x4001c024 (1) access: write-only the following configuration values are valid for all listed bit names of this register. 0 = no effect. 1 = enables the corresponding interrupt. ? txcomp: transmission completed interrupt enable ? rxrdy: receive holding register ready interrupt enable ? txrdy: transmit holding register ready interrupt enable ? svacc: slave access interrupt enable ? gacc: general call access interrupt enable ? ovre: overrun error interrupt enable ? nack: not acknowledge interrupt enable ? arblst: arbitration lost interrupt enable ? scl_ws: clock wait state interrupt enable ? eosacc: end of slave access interrupt enable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? rxbuff: receive buffer full interrupt enable ? txbufe: transmit buffer empty interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc scl_ws arblst nack 76543210 ? ovre gacc svacc ? txrdy rxrdy txcomp
712 sam4cp [datasheet] 43051e?atpl?08/14 34.8.8 twi interrupt disable register name: twi_idr address: 0x40018028 (0), 0x4001c028 (1) access: write-only the following configuration values are valid for all listed bit names of this register. 0 = no effect. 1 = disables the corresponding interrupt. ? txcomp: transmission completed interrupt disable ? rxrdy: receive holding register ready interrupt disable ? txrdy: transmit holding register ready interrupt disable ? svacc: slave access interrupt disable ? gacc: general call access interrupt disable ? ovre: overrun error interrupt disable ? nack: not acknowledge interrupt disable ? arblst: arbitration lost interrupt disable ? scl_ws: clock wait state interrupt disable ? eosacc: end of slave access interrupt disable ? endrx: end of receive buffer interrupt disable ? endtx: end of transmit buffer interrupt disable ? rxbuff: receive buffer full interrupt disable ? txbufe: transmit buffer empty interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc scl_ws arblst nack 76543210 ? ovre gacc svacc ? txrdy rxrdy txcomp
713 sam4cp [datasheet] 43051e?atpl?08/14 34.8.9 twi interrupt mask register name: twi_imr address: 0x4001802c (0), 0x4001c02c (1) access: read-only the following configuration values are valid for all listed bit names of this register. 0 = the corresponding interrupt is disabled. 1 = the corresponding interrupt is enabled. ? txcomp: transmission completed interrupt mask ? rxrdy: receive holding register ready interrupt mask ? txrdy: transmit holding register ready interrupt mask ? svacc: slave access interrupt mask ? gacc: general call access interrupt mask ? ovre: overrun error interrupt mask ? nack: not acknowledge interrupt mask ? arblst: arbitration lost interrupt mask ? scl_ws: clock wait state interrupt mask ? eosacc: end of slave access interrupt mask ? endrx: end of receive buffer interrupt mask ? endtx: end of transmit buffer interrupt mask ? rxbuff: receive buffer full interrupt mask ? txbufe: transmit buffer empty interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txbufe rxbuff endtx endrx eosacc scl_ws arblst nack 76543210 ? ovre gacc svacc ? txrdy rxrdy txcomp
714 sam4cp [datasheet] 43051e?atpl?08/14 34.8.10 twi receive holding register name: twi_rhr address: 0x40018030 (0), 0x4001c030 (1) access: read-only ? rxdata: master or slave receive holding data 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 rxdata
715 sam4cp [datasheet] 43051e?atpl?08/14 34.8.11 twi transmit holding register name: twi_thr address: 0x40018034 (0), 0x4001c034 (1) access: write-only ? txdata: master or slave transmit holding data 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 txdata
716 sam4cp [datasheet] 43051e?atpl?08/14 34.8.12 twi write protection mode register name: twi_wpmr address: 0x400180e4 (0), 0x4001c0e4 (1) access: read/write ? wpen: write protection enable 0 = disables the write protection if wpkey corresponds to 0x545749 (?twi? in ascii). 1 = enables the write protection if wpkey corresponds to 0x545749 (?twi? in ascii). see section 34.7.6 ?register write protection? for the list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x545749 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
717 sam4cp [datasheet] 43051e?atpl?08/14 34.8.13 twi write protection status register name: twi_wpsr address: 0x400180e8 (0), 0x4001c0e8 (1) access: read-only ? wpvs: write protection violation status 0: no write protection violation has occurred since the last read of the twi_wpsr. 1: a write protection violation has occurred since the last read of the twi_wpsr. if this violation is an unauthorized attempt to write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 wpvsrc 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
718 sam4cp [datasheet] 43051e?atpl?08/14 35. universal asynchronous receiver transmitter (uart) 35.1 description the universal asynchronous receiver transmitter (uart) features a two-pin uart that can be used for communication and trace purposes and offers an ideal medium for in-situ programming solutions. moreover, the association with a peripheral dma controller (pdc) permits packet handling for these tasks with processor time reduced to a minimum. the optical link transceiver establishes electrically isolated serial communication with hand-held equipment, such as calibrators compliant with ansi-c12.18 or iec62056-21 norms. 35.2 embedded characteristics ? two-pin uart ? independent receiver and transmitter with a common programmable baud rate generator ? even, odd, mark or space parity generation ? parity, framing and overrun error detection ? automatic echo, local loopback and remote loopback channel modes ? digital filter on receive line ? interrupt generation ? support for two pdc channels with connection to receiver and transmitter ? optical link transceiver for communication compliant with ansi-c12.18 or iec62056-21 norms 35.3 block diagram figure 35-1. uart functional block diagram table 35-1. uart pin description pin name description type urxd uart receive data input utxd uart transmit data output peripheral dma controller baud rate generator transmit receive interrupt control parallel input/ output utxd urxd uart_irq apb bus clock bridge peripheral clock pmc uart
719 sam4cp [datasheet] 43051e?atpl?08/14 35.4 product dependencies 35.4.1 i/o lines the uart pins are multiplexed with pio lines. the user must first configure the corresponding pio controller to enable i/o line operations of the uart. 35.4.2 power management the uart clock can be controlled through the power management controller (pmc). in this case, the user must first configure the pmc to enable the uart clock. usually, the peripheral identifier used for this purpose is 1. 35.4.3 interrupt source the uart interrupt line is connected to one of the interrupt sources of the interrupt controller. interrupt handling requires programming of the interrupt controller before configuring the uart. 35.4.4 optical interface the uart optical interface requires configuration of the pmc to generate 4096 khz or 8192 khz on the plla prior to any transfer. 35.5 functional description the uart operates in asynchronous mode only and supports only 8-bit character handling (with parity). it has no clock pin. the uart is made up of a receiver and a transmitter that operate independently, and a common baud rate generator. receiver timeout and transmitter time guard are not implemented. however, all the implemented features are compatible with those of a standard usart. 35.5.1 baud rate generator the baud rate generator provides the bit period clock named baud rate clock to both the receiver and the transmitter. the baud rate clock is the peripheral clock divided by 16 times the clock divisor (cd) value written in the baud rate generator register (uart_brgr). if uart_brgr is set to 0, the baud rate clock is disabled and the uart remains inactive. the maximum allowable baud rate is peripheral clock divided by 16. the minimum allowable baud rate is peripheral clock divided by (16 x 65536). table 35-2. i/o lines instance signal i/o line peripheral uart0 urxd0 pb4 a uart0 utxd0 pb5 a uart1 urxd1 pc1 a uart1 utxd1 pc0 a baud rate fperipheral clock 16 cd ? ------------------------------------------- =
720 sam4cp [datasheet] 43051e?atpl?08/14 figure 35-2. baud rate generator 35.5.2 receiver 35.5.2.1 receiver reset, enable and disable after device reset, the uart receiver is disabled and must be enabled before being used. the receiver can be enabled by writing the control register (uart_cr) with the bit rxen at 1. at this command, the receiver starts looking for a start bit. the programmer can disable the receiver by writing uart_cr with the bit rxdis at 1. if the receiver is waiting for a start bit, it is immediately stopped. however, if the receiver has al ready detected a start bit and is receiving the data, it waits for the stop bit before actually stopping its operation. the receiver can be put in reset state by writing uart_cr with the bit rstrx at 1. in this case, the receiver immediately stops its current operations and is disabled, whatever its current state. if rstrx is applied when data is being processed, this data is lost. 35.5.2.2 start detection and data sampling the uart only supports asynchronous operations, and this affects only its receiver. the uart receiver detects the start of a received character by sampling the urxd signal until it detects a valid start bit. a low level (space) on urxd is interpreted as a valid start bit if it is detected for more than seven cycles of the sampling clock, which is 16 times the baud rate. hence, a space that is longer than 7/16 of the bit period is detected as a valid start bit. a space which is 7/16 of a bi t period or shorter is ignored and the receiver continues to wait for a valid start bit. when a valid start bit has been detected, the receiver samples the urxd at the theoretical midpoint of each bit. it is assumed that each bit lasts 16 cycles of the sampling clock (1-bit period) so the bit sampling point is eight cycles (0.5-bit period) after the start of the bit. the first sampling point is therefore 24 cycles (1.5-bit periods) after detecting the falli ng edge of the start bit. each subsequent bit is sampled 16 cycles (1-bit period) after the previous one. figure 35-3. start bit detection 0 0 1 >1 cd cd peripheral clock 16-bit counter out divide by 16 baud rate clock receiver sampling clock d0 d1 d2 d3 d4 d5 d6 d7 p s s d0 d1 d2 d3 d4 d5 d6 d7 p urxd rstst a rxrdy ovre stop stop
721 sam4cp [datasheet] 43051e?atpl?08/14 figure 35-4. character reception 35.5.2.3 receiver ready when a complete character is received, it is transferre d to the receive holding register (uart_rhr) and the rxrdy status bit in the status register (uart_sr) is set. the bit rxrdy is automatically cleared when uart_rhr is read. figure 35-5. receiver ready 35.5.2.4 receiver overrun the ovre status bit in uart_sr is set if uart_rhr has not been read by the software (or the pdc) since the last transfer, the rxrdy bit is still set and a new character is received. ovre is cleared when the software writes a 1 to the bit rststa (reset status) in uart_cr. figure 35-6. receiver overrun 35.5.2.5 parity error each time a character is received, the receiver calculates the parity of the received data bits, in accordance with the field par in the mode register (uart_mr). it then compares the result with the received parity bit. if different, the parity error bit pare in uart_sr is set at the same time rxrdy is set. the parity bit is cleared when uart_cr is written with the bit rststa (reset status) at 1. if a new character is received before the reset status command is written, the pare bit remains at 1. d0 d1 d2 d3 d4 d5 d6 d7 urxd true start detection sampling parity bit stop b it example: 8-bit, parity enabled 1 stop 1 bit period 0.5 bit period d0 d1 d2 d3 d4 d5 d6 d7 p s s d0 d1 d2 d3 d4 d5 d6 d7 p urxd read uart_rhr r xrdy d0 d1 d2 d3 d4 d5 d6 d7 p s s d0 d1 d2 d3 d4 d5 d6 d7 p urxd rstst a r xrdy ovre stop stop
722 sam4cp [datasheet] 43051e?atpl?08/14 figure 35-7. parity error 35.5.2.6 receiver framing error when a start bit is detected, it generates a character reception when all the data bits have been sampled. the stop bit is also sampled and when it is detected at 0, the frame (framing error) bit in uart_sr is set at the same time the rxrdy bit is set. the frame bit remains high until the control register (uart_cr) is written with the bit rststa at 1. figure 35-8. receiver framing error 35.5.2.7 receiver digital filter the uart embeds a digital filter on the receive line. it is disabled by default and can be enabled by writing a logical 1 in the filter bit of uart_mr. when enabled, the receive line is sampled using the 16x bit clock and a three-sample filter (majority 2 over 3) determines the value of the line. 35.5.3 transmitter 35.5.3.1 transmitter reset, enable and disable after device reset, the uart transmitter is disabled and must be enabled before being used. the transmitter is enabled by writing uart_cr with the bit txen at 1. from this command, the transmitter waits for a character to be written in the transmit holding register (uart_thr) before actually starting the transmission. the programmer can disable the transmitter by writing uart_cr with the bit txdis at 1. if the transmitter is not operating, it is immediately stopped. howev er, if a character is being processed into the internal shift register and/or a character has been written in the uart_thr, the characters are completed before the transmitter is actually stopped. the programmer can also put the transmitter in its reset state by writing the uart_cr with the bit rsttx at 1. this immediately stops the transmitter, whether or not it is processing characters. 35.5.3.2 transmit format the uart transmitter drives the pin utxd at the baud rate clock speed. the line is driven depending on the format defined in uart_mr and the data stored in the internal shift register. one start bit at level 0, then the 8 data bits, from the lowest to the highest bit, one optional parity bit and one stop bit at 1 are consecutively shifted out as shown in the following figure. the field pare in uart_mr defines whether or not a parity bit is shifted out. when a parity bit is enabled, it can be selected between an odd parity, an even parity, or a fixed space or mark bit. stop d0 d1 d2 d3 d4 d5 d6 d7 p s urxd rststa r xrdy pare wrong parity bit d0 d1 d2 d3 d4 d5 d6 d7 p s urxd rststa r xrdy f rame stop bit detected at 0 stop
723 sam4cp [datasheet] 43051e?atpl?08/14 figure 35-9. character transmission 35.5.3.3 transmitter control when the transmitter is enabled, the bit txrdy (transmitter ready) is set in uart_sr. the transmission starts when the programmer writes in the uart_thr, and after the written character is transferred from uart_thr to the internal shift register. the txrdy bit remains high until a second character is written in uart_thr. as soon as the first character is completed, the last character written in uart_thr is transferred into the internal shift register and txrdy rises again, showing that the holding register is empty. when both the internal shift register and uart_thr are empty, i.e., all the characters written in uart_thr have been processed, the txempty bit rises after the last stop bit has been completed. figure 35-10. transmitter control 35.5.4 optical interface to use the optical interface circuitry, the plla clock must be ready and programmed to generate a frequency within the range of 4096 up to 8192 khz. this range allows a modulation by a clock with an adjustable frequency from 30 up to 60 khz. the optical interface is enabled by writing a 1 to the bit opt_en in uart_mr (see ?uart mode register? on page 728 ). when opt_en=1, the urxd pad is automatically configured in analog mode and the analog comparator is enabled (see figure 35-11 on page 724 ). to match the characteristics of the off-chip optical receiver circuitry, the voltage reference threshold of the embedded comparator can be adjusted from vddio/10 up to vdd/2 by programming the opt_cmpth field in uart_mr. the nrz output of the uart transmitter sub-module is modulated with the 30 up to 60 khz modulation clock prior to driving the pio controller. a logical 0 on the uart transmitter sub-module output generates the said modulated signal (see figure 35-12 on page 724 ) having a frequency programmable from 30 khz up to 60 khz (38 khz is the default value assuming the plla clock d0 d1 d2 d3 d4 d5 d6 d7 utxd start bit parity bit stop bit example: parity enabled b aud rate clock uart_thr s hift register utxd txrdy txempty data 0 data 1 data 0 data 0 data 1 data 1 s s p p write data 0 in uart_thr write data 1 in uart_thr stop stop
724 sam4cp [datasheet] 43051e?atpl?08/14 frequency is 8192 khz). a logical 1 on the uart transmitter sub-module output generates a stuck-at 1 output signal (no modulation). the idle polarity of the modulated signal is 1 (opt_mdinv=0 in uart_mr). the idle polarity of the modulated signal can be inverted by writing a 1 to the opt_mdinv bit in uart_mr. the duty cycle of the modulated signal can be adjusted from 6.25% up to 50% (default value) by steps of 6.25% by programming the opt_duty field in uart_mr. figure 35-11. optical interface block diagram figure 35-12. optical interface waveforms opt_en opt_clkdiv opt_duty opt_mdinv opt_cmpth opt_en baud rate generator transmit receive interrupt control power management controller peripheral clock uart_irq uar t pllack 0 pio_irq 1 on optical clock divider optical duty cycle generator /8 1 optical modulation parallel input/ output utxd urxd analog comparator 0 vth opt_en opt_rxinv optica l receive lo g ic uart transmitter ouput utxd (opt_mdinv = 1) utxd (opt_mdinv = 0) t peripheral clock * ( 8 * (opt_clkdiv + 8) ) opt_duty = 0 opt_duty = 3 opt_duty = 7 utxd (opt_en = 0) opt_en = 1 opt_mdinv = 0
725 sam4cp [datasheet] 43051e?atpl?08/14 the default configuration values of the optical link circuitries allow the 38 khz modulation, a 50% duty cycle and an idle polarity allowing a direct drive of an ir led through a resistor (see figure 35-13 on page 725 ). refer to the electrical characteristics section for drive capability of the buffer associated with the utxd output. in case of direct drive of the ir led as shown in figure 35-13 on page 725 , the pio must be programmed in multi-driver mode (open-drain). to do so, the adequate index and values must be programmed into the pio multi-driver enable register (pio_mder) (status reported on the pio multi-driver status register (pio_mdsr)). refer to the parallel input/output controller (pio) section for details. if an off-chip current amplifier is used to drive the transmitting of the ir led, the pio may be programmed in default drive mode (non open-drain) for the line index driving the utxd output, or in open-drain mode depending on the type of external circuitry. figure 35-13. optical interface connected to ir components 35.5.5 peripheral dma controller (pdc) both the receiver and the transmitter of the uart are connected to a pdc. the pdc channels are programmed via registers that are mapped within the uart user interface from the offset 0x100. the status bits are reported in uart_sr and generate an interrupt. the rxrdy bit triggers the pdc channel data transfer of the receiver. this results in a read of the data in uart_rhr. the txrdy bit triggers the pdc channel data transfer of the transmitter. this results in a write of data in uart_thr. 35.5.6 test modes the uart supports three test modes. these modes of operation are programmed by using the chmode field in uart_mr. the automatic echo mode allows bit-by-bit retransmission. when a bit is received on the urxd line, it is sent to the utxd line. the transmitter operates normally, but has no effect on the utxd line. the local loopback mode allows the transmitted characters to be received. utxd and urxd pins are not used and the output of the transmitter is internally connected to the input of the receiver. the urxd pin level has no effect and the utxd line is held high, as in idle state. the remote loopback mode directly connects the urxd pin to the utxd line. the transmitter and the receiver are disabled and have no effect. this mode allows a bit-by-bit retransmission. uar t pio utxd urxd t x d r x d resistor pio_mdsr [utxd] i.r. led vddio vddio phototransistor 1 1 0 0 0 0
726 sam4cp [datasheet] 43051e?atpl?08/14 figure 35-14. test modes 35.6 universal asynchronous receiver transmitter (uart) user interface receiver transmitter disabled rx d tx d receiver transmitter disabled rx d tx d v dd disabled receiver transmitter disabled rx d tx d disabled automatic echo local loopback r emote loopback v dd table 35-3. register mapping offset register name access reset 0x0000 control register uart_cr write-only ? 0x0004 mode register uart_mr read/write 0x0013_0000 0x0008 interrupt enable register uart_ier write-only ? 0x000c interrupt disable register uart_idr write-only ? 0x0010 interrupt mask register uart_imr read-only 0x0 0x0014 status register uart_sr read-only ? 0x0018 receive holding register uart_rhr read-only 0x0 0x001c transmit holding register uart_thr write-only ? 0x0020 baud rate generator register uart_brgr read/write 0x0 0x0024 - 0x003c reserved ? ? ? 0x0040 - 0x00e8 reserved ? ? ? 0x00ec - 0x00fc reserved ? ? ? 0x0100 - 0x0128 reserved for pdc registers ? ? ?
727 sam4cp [datasheet] 43051e?atpl?08/14 35.6.1 uart control register name: uart_cr address: 0x400e0600 (0), 0x48004000 (1) access: write-only ? rstrx: reset receiver 0 = no effect. 1 = the receiver logic is reset and disabled. if a character is being received, the reception is aborted. ? rsttx: reset transmitter 0 = no effect. 1 = the transmitter logic is reset and disabled. if a character is being transmitted, the transmission is aborted. ? rxen: receiver enable 0 = no effect. 1 = the receiver is enabled if rxdis is 0. ? rxdis: receiver disable 0 = no effect. 1 = the receiver is disabled. if a character is being processed and rstrx is not set, the character is completed before the receiver is stopped. ? txen: transmitter enable 0 = no effect. 1 = the transmitter is enabled if txdis is 0. ? txdis: transmitter disable 0 = no effect. 1 = the transmitter is disabled. if a character is being processed and a character has been written in the uart_thr and rsttx is not set, both characters are completed before the transmitter is stopped. ? rststa: reset status 0 = no effect. 1 = resets the status bits pare, frame and ovre in the uart_sr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ??????? rststa 76543210 txdis txen rxdis rxen rsttx rstrx ? ?
728 sam4cp [datasheet] 43051e?atpl?08/14 35.6.2 uart mode register name: uart_mr address: 0x400e0604 (0), 0x48004004 (1) access: read/write ? opt_en: uart optical interface enable ? opt_rxinv: uart receive data inverted ? opt_mdinv: uart modulated data inverted ? filter: receiver digital filter 0 (disabled) = uart does not filter the receive line. 1 (enabled) = uart filters the receive line using a three-sample filter (16x-bit clock) (2 over 3 majority). 31 30 29 28 27 26 25 24 ? opt_cmpth ? opt_duty 23 22 21 20 19 18 17 16 ? ? ? opt_clkdiv 15 14 13 12 11 10 9 8 chmode ? ? par ? 76543210 ? ? ? filter ? opt_mdinv opt_rxinv opt_en value name description 0 disabled the uart transmitter data is not inverted before modulation. 1 enabled the uart transmitter data is inverted before modulation. value name description 0 disabled the comparator data output is not inverted before entering uart. 1 enabled the comparator data output is inverted before entering uart. value name description 0 disabled the output of the modulator is not inverted. 1 enabled the output of the modulator is inverted.
729 sam4cp [datasheet] 43051e?atpl?08/14 ? par: parity type ? chmode: channel mode ? opt_clkdiv: optical link clock divider 0 to 31 = the optical modulation clock frequency is defined by pllack / (8*(opt_clkdiv+8)). ? opt_duty: optical link modulation clock duty cycle ? opt_cmpth: receive path comparator threshold value name description 0 even even parity 1 odd odd parity 2 space space: parity forced to 0 3 mark mark: parity forced to 1 4 no no parity value name description 0 normal normal mode 1 automatic automatic echo 2 local_loopback local loopback 3 remote_loopback remote loopback value name description 0 duty_50 modulation clock duty cycle is 50%. 1 duty_43p75 modulation clock duty cycle is 43.75%. 2 duty_37p5 modulation clock duty cycle is 37.5%. 3 duty_31p25 modulation clock duty cycle is 31.75%. 4 duty_25 modulation clock duty cycle is 25%. 5 duty_18p75 modulation clock duty cycle is 18.75%. 6 duty_12p5 modulation clock duty cycle is 12.5%. 7 duty_6p25 modulation clock duty cycle is 6.25%. value name description 0 vddio_div2 comparator threshold is vddio/2 volts. 1 vddio_div2p5 comparator threshold is vddio/2.5 volts. 2 vddio_div3p3 comparator threshold is vddio/3.3 volts. 3 vddio_div5 comparator threshold is vddio/5 volts. 4 vddio_div10 comparator threshold is vddio/10 volts.
730 sam4cp [datasheet] 43051e?atpl?08/14 35.6.3 uart interrupt enable register name: uart_ier address: 0x400e0608 (0), 0x48004008 (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0 = no effect. 1 = enables the corresponding interrupt. ? rxrdy: enable rxrdy interrupt ? txrdy: enable txrdy interrupt ? endrx: enable end of receive transfer interrupt ? endtx: enable end of transmit interrupt ? ovre: enable overrun error interrupt ? frame: enable framing error interrupt ? pare: enable parity error interrupt ? txempty: enable txempty interrupt ? txbufe: enable buffer empty interrupt ? rxbuff: enable buffer full interrupt 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
731 sam4cp [datasheet] 43051e?atpl?08/14 35.6.4 uart interrupt disable register name: uart_idr address: 0x400e060c (0), 0x4800400c (1) access: write-only the following configuration values are valid for all listed bit names of this register: 0 = no effect. 1 = disables the corresponding interrupt. ? rxrdy: disable rxrdy interrupt ? txrdy: disable txrdy interrupt ? endrx: disable end of receive transfer interrupt ? endtx: disable end of transmit interrupt ? ovre: disable overrun error interrupt ? frame: disable framing error interrupt ? pare: disable parity error interrupt ? txempty: disable txempty interrupt ? txbufe: disable buffer empty interrupt ? rxbuff: disable buffer full interrupt 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
732 sam4cp [datasheet] 43051e?atpl?08/14 35.6.5 uart interrupt mask register name: uart_imr address: 0x400e0610 (0), 0x48004010 (1) access: read-only the following configuration values are valid for all listed bit names of this register: 0 = the corresponding interrupt is disabled. 1 = the corresponding interrupt is enabled. ? rxrdy: mask rxrdy interrupt ? txrdy: disable txrdy interrupt ? endrx: mask end of receive transfer interrupt ? endtx: mask end of transmit interrupt ? ovre: mask overrun error interrupt ? frame: mask framing error interrupt ? pare: mask parity error interrupt ? txempty: mask txempty interrupt ? txbufe: mask txbufe interrupt ? rxbuff: mask rxbuff interrupt 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
733 sam4cp [datasheet] 43051e?atpl?08/14 35.6.6 uart status register name: uart_sr address: 0x400e0614 (0), 0x48004014 (1) access: read-only ? rxrdy: receiver ready 0 = no character has been received since the last read of the uart_rhr or the receiver is disabled. 1 = at least one complete character has been received, transferred to uart_rhr and not yet read. ? txrdy: transmitter ready 0 = a character has been written to uart_thr and not yet transferred to the internal shift register, or the transmitter is disa bled. 1 = there is no character written to uart_thr not yet transferred to the internal shift register. ? endrx: end of receiver transfer 0 = the end of transfer signal from the receiver pdc channel is inactive. 1 = the end of transfer signal from the receiver pdc channel is active. ? endtx: end of transmitter transfer 0 = the end of transfer signal from the transmitter pdc channel is inactive. 1 = the end of transfer signal from the transmitter pdc channel is active. ? ovre: overrun error 0 = no overrun error has occurred since the last rststa. 1 = at least one overrun error has occurred since the last rststa. ? frame: framing error 0 = no framing error has occurred since the last rststa. 1 = at least one framing error has occurred since the last rststa. ? pare: parity error 0 = no parity error has occurred since the last rststa. 1 = at least one parity error has occurred since the last rststa. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe ? txempty ? 76543210 pare frame ovre endtx endrx ? txrdy rxrdy
734 sam4cp [datasheet] 43051e?atpl?08/14 ? txempty: transmitter empty 0 = there are characters in uart_thr, or characters being processed by the transmitter, or the transmitter is disabled. 1 = there are no characters in uart_thr and there are no characters being processed by the transmitter. ? txbufe: transmission buffer empty 0 = the buffer empty signal from the transmitter pdc channel is inactive. 1 = the buffer empty signal from the transmitter pdc channel is active. ? rxbuff: receive buffer full 0 = the buffer full signal from the receiver pdc channel is inactive. 1 = the buffer full signal from the receiver pdc channel is active.
735 sam4cp [datasheet] 43051e?atpl?08/14 35.6.7 uart receiver holding register name: uart_rhr address: 0x400e0618 (0), 0x48004018 (1) access: read-only ? rxchr: received character last received character if rxrdy is set. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 rxchr
736 sam4cp [datasheet] 43051e?atpl?08/14 35.6.8 uart transmit holding register name: uart_thr address: 0x400e061c (0), 0x4800401c (1) access: write-only ? txchr: character to be transmitted next character to be transmitted after the current character if txrdy is not set. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 txchr
737 sam4cp [datasheet] 43051e?atpl?08/14 35.6.9 uart baud rate generator register name: uart_brgr address: 0x400e0620 (0), 0x48004020 (1) access: read/write ? cd: clock divisor 0 = baud rate clock is disabled. 1 to 65,535 = f peripheral clock / (cd x 16). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 cd 76543210 cd
738 sam4cp [datasheet] 43051e?atpl?08/14 36. universal synchronous asynchronous receiver transceiver (usart) 36.1 description the universal synchronous asynchronous receiver transceiver (usart) provides one full duplex universal synchronous asynchronous serial link. data frame format is widely programmable (data length, parity, number of stop bits) to support a maximum of standards. the receiver implements parity error, framing error and overrun error detection. the receiver time-out enables handling variable-length frames and the transmitter timeguard facilitates communications with slow remote devices. multidrop communications are also supported through address bit handling in reception and transmission. the usart features three test modes: remote loopback, local loopback and automatic echo. the usart supports specific operating modes providing interfaces on rs485 and spi buses, with iso7816 t = 0 or t = 1 smart card slots and infrared transceivers. the hardware handshaking feature enables an out-of-band flow control by automatic management of the pins rts and cts. the usart supports the connection to th e peripheral dma controller, which enabl es data transfers to the transmitter and from the receiver. the pdc provides chained buffer management without any intervention of the processor. 36.2 embedded characteristics ? programmable baud rate generator ? 5- to 9-bit full-duplex synchronous or asynchronous serial communications ? 1, 1.5 or 2 stop bits in asynchronous mode or 1 or 2 stop bits in synchronous mode ? parity generation and error detection ? framing error detection, overrun error detection ? digital filter on receive line ? msb- or lsb-first ? optional break generation and detection ? by 8 or by 16 over-sampling receiver frequency ? optional hardware handshaking rts-cts ? receiver time-out and transmitter timeguard ? optional multidrop mode with address generation and detection ? rs485 with driver control signal ? iso7816, t = 0 or t = 1 protocols for interfacing with smart cards ? nack handling, error counter with repetition and iteration limit ? irda modulation and demodulation ? communication at up to 115.2 kbps ? spi mode ? master or slave ? serial clock programmable phase and polarity ? spi serial clock (sck) frequency up to f peripheral clock /6 ? test modes ? remote loopback, local loopback, automatic echo ? supports connection of: ? two peripheral dma controller channels (pdc) ? offers buffer transfer without processor intervention ? register write protection
739 sam4cp [datasheet] 43051e?atpl?08/14 36.3 block diagram figure 36-1. usart block diagram 36.4 i/o lines description (peripheral) dma controller channel channel interrupt controller receiver usart interrupt rxd txd sck usart pio controller cts rts transmitter baud rate generator pmc peripheral clock apb peripheral clock/div bus clock bridge user interface table 36-1. i/o line description name description type active level sck serial clock i/o -- txd transmit serial data or master out slave in (mosi) in spi master mode or master in slave out (miso) in spi slave mode i/o -- rxd receive serial data or master in slave out (miso) in spi master mode or master out slave in (mosi) in spi slave mode input -- cts clear to send or slave select (nss) in spi slave mode input low rts request to send or slave select (nss) in spi master mode output low
740 sam4cp [datasheet] 43051e?atpl?08/14 36.5 product dependencies 36.5.1 i/o lines the pins used for interfacing the usart may be multiplexed with the pio lines. the programmer must first program the pio controller to assign the desired usart pins to their peripheral function. if i/o lines of the usart are not used by the application, they can be used for other purposes by the pio controller. to prevent the txd line from falling when the usart is disabled, the use of an internal pull up is mandatory. if the hardware handshaking feature is used, the internal pull up on txd must also be enabled. 36.5.2 power management the usart is not continuously clocked. the programmer must first enable the usart clock in the power management controller (pmc) before using the usart. however, if the application does not require usart operations, the usart clock can be stopped when not needed and be restarted later. in this case, the usart will resume its operations where it left off. table 36-2. i/o lines instance signal i/o line peripheral usart0 cts0 pa20 a usart0 rts0 pa19 a usart0 rxd0 pb16 a usart0 sck0 pb18 a usart0 txd0 pb17 a usart1 cts1 pa18 a usart1 rts1 pa17 a usart1 rxd1 pa11 a usart1 sck1 pa16 a usart1 txd1 pa12 a usart2 cts2 pa15 a usart2 rts2 pa14 a usart2 rxd2 pa9 a usart2 sck2 pa13 a usart2 txd2 pa10 a usart3 cts3 pa1 a usart3 rts3 pa0 a usart3 rxd3 pa3 a usart3 sck3 pa2 a usart3 txd3 pa4 a usart4 cts4 pa26 a usart4 rts4 pb22 a usart4 rxd4 pb19 a usart4 sck4 pb21 a usart4 txd4 pb20 a
741 sam4cp [datasheet] 43051e?atpl?08/14 36.5.3 interrupt the usart interrupt line is connected on one of the internal sources of the interrupt controller. using the usart interrupt requires the interrupt controller to be programmed first. 36.6 functional description 36.6.1 baud rate generator the baud rate generator provides the bit period clock, also named the baud rate clock to both the receiver and the transmitter. the baud rate generator clock source is selected by configuring the usclks field in the usart mode register (us_mr) to one of the following: ? the peripheral clock. ? a division of the peripheral clock, where the divider is product-dependent, but generally set to 8. ? the external clock, available on the sck pin. the baud rate generator is based upon a 16-bit divider, which is programmed with the cd field of the baud rate generator register (us_brgr). if a zero is written to cd, the baud rate gene rator does not generate any clock. if a one is written to cd, the divider is bypassed and becomes inactive. if the external sck clock is selected, the duration of the low and high levels of the signal provided on the sck pin must be longer than a peripheral clo ck period. the frequency of the signal provided on sck must be at least 3 times lower than the frequency provided on the peripheral clock in usart mode (field usart_mode differs from 0xe or 0xf), or 6 times lower in spi mode (field usart_mode equals 0xe or 0xf). figure 36-2. baud rate generator table 36-3. peripheral ids instance id usart0 14 usart1 15 usart2 16 usart3 17 usart4 18 peripheral clock/div 16-bit counter 0 baud rate clock cd cd sampling divider 0 1 >1 sampling clock reserved peripheral clock sck (clko = 0) usclks over sck (clko = 1) sync sync usclks = 3 1 0 2 3 0 1 0 1 fidi
742 sam4cp [datasheet] 43051e?atpl?08/14 36.6.1.1 baud rate in asynchronous mode if the usart is programmed to operate in asynchronous mode, th e selected clock is first divided by cd, which is field programmed in the us_brgr. the resulting clock is provided to the receiver as a sampling clock and then divided by 16 or 8, depending on how the over bit in the us_mr is programmed. if over is set, the receiver sampling is 8 times higher than the baud rate clock. if over is cleared, the sampling is performed at 16 times the baud rate clock. the baud rate is calculated as per the following formula: this gives a maximum baud rate of peripheral clock divided by 8, assuming that peripheral clock is the highest possible clock and that the over bit is set. baud rate calculation example table 36-4 shows calculations of cd to obtain a baud rate at 38400 bit/s for different source clock frequencies. this table also shows the actual resulting baud rate and the error. the baud rate is calculated with the following formula: the baud rate error is calculated with the following formula. it is not recommended to work with an error higher than 5%. baudrate selectedclock 82 over ? ?? cd ?? ---------------------------------------------- = table 36-4. baud rate example (over = 0) source clock (hz) expected baud rate (bit/s) calculation result cd actual baud rate (bit/s) error 3 686 400 38 400 6.00 6 38 400.00 0.00% 4 915 200 38 400 8.00 8 38 400.00 0.00% 5 000 000 38 400 8.14 8 39 062.50 1.70% 7 372 800 38 400 12.00 12 38 400.00 0.00% 8 000 000 38 400 13.02 13 38 461.54 0.16% 12 000 000 38 400 19.53 20 37 500.00 2.40% 12 288 000 38 400 20.00 20 38 400.00 0.00% 14 318 180 38 400 23.30 23 38 908.10 1.31% 14 745 600 38 400 24.00 24 38 400.00 0.00% 18 432 000 38 400 30.00 30 38 400.00 0.00% 24 000 000 38 400 39.06 39 38 461.54 0.16% 24 576 000 38 400 40.00 40 38 400.00 0.00% 25 000 000 38 400 40.69 40 38 109.76 0.76% 32 000 000 38 400 52.08 52 38 461.54 0.16% 32 768 000 38 400 53.33 53 38 641.51 0.63% 33 000 000 38 400 53.71 54 38 194.44 0.54% 40 000 000 38 400 65.10 65 38 461.54 0.16% 50 000 000 38 400 81.38 81 38 580.25 0.47% baudrate fperiperalclock cd 16 ? ? = error 1 expectedbaudrate actualbaudrate -------------------------------------------------------- - ?? ?? ? =
743 sam4cp [datasheet] 43051e?atpl?08/14 36.6.1.2 fractional baud rate in asynchronous mode the baud rate generator is subject to the following limitation: the output frequency changes only by integer multiples of the reference frequency. an approach to this problem is to integrate a fractional n clock generator that has a high resolution. the generator architecture is modified to obtain baud rate changes by a fraction of the reference source clock. this fractional part is programmed with the fp field in the us_brgr. if fp is not 0, the fractional part is activated. the resolution is one eighth of the clock divider. this feature is only available when using usart normal mode. the fractional baud rate is calculated using the following formula: the modified architecture is presented in the following figure: figure 36-3. fractional baud rate generator 36.6.1.3 baud rate in synchronous mode or spi mode if the usart is programmed to operate in synchronous mode, the selected clock is simply divided by the field cd in the us_brgr. in synchronous mode, if the external clock is selected (usclks = 3), the clock is provided directly by the signal on the usart sck pin. no division is active. the value written in us_brgr has no effect. the external clock frequency must be at least 3 times lower than the system clock. in synchronous mode master (usclks = 0 or 1, clko set to 1), the receive part limits the sck maximum frequency to f peripheral clock /3 in usart mode, or f peripheral clock /6 in spi mode. when either the external clock sck or the internal clock divided (peripheral clock/div) is selected, the value programmed in cd must be even if the user has to ensure a 50:50 mark/space ratio on the sck pin. when the peripheral clock is selected, the baud rate generator ensures a 50:50 duty cycle on the sck pin, even if the value programmed in cd is odd. 36.6.1.4 baud rate in iso 7816 mode the iso7816 specification defines the bit rate with the following formula: baudrate selectedclock 82 over ? ?? cd fp 8 ------- - + ?? ?? ?? ?? ------------------------------------------------------------------- = peripheral clock/div 16-bit counter 0 baud rate clock cd cd sampling divider 0 1 >1 sampling clock reserved peripheral clock sck (clko = 0) usclks over sck (clko = 1) sync sync usclks = 3 1 0 2 3 0 1 0 1 fidi glitch-free logic modulus control fp fp baudrate selectedclock cd ------------------------------------------ = b di fi ----- - f ? =
744 sam4cp [datasheet] 43051e?atpl?08/14 where: ? b is the bit rate. ? di is the bit-rate adjustment factor. ? fi is the clock frequency division factor. ? f is the iso7816 clock frequency (hz). di is a binary value encoded on a 4-bit field, named di, as represented in table 36-5 . fi is a binary value encoded on a 4-bit field, named fi, as represented in table 36-6 . table 36-7 shows the resulting fi/di ratio, which is the ratio between the iso7816 clock and the baud rate clock. if the usart is configured in iso7816 mode, the clock selected by the usclks field in the us_mr is first divided by the value programmed in the field cd in the us_brgr. the resulting clock can be provided to the sck pin to feed the smart card clock inputs. this means that the clko bit can be set in us_mr. this clock is then divided by the value programmed in the fi_di_ratio field in the fi_di_ratio register (us_fidi). this is performed by the sampling divider, which performs a division by up to 2047 in iso7816 mode. the non-integer values of the fi/di ratio are not supported and the user must program the fi_di_ratio field to a value as close as possible to the expected value. the fi_di_ratio field resets to the value 0x174 (372 in decimal) and is the most common divider between the iso7816 clock and the bit rate (fi = 372, di = 1). table 36-5. binary and decimal values for di di field 0001 0010 0011 0100 0101 0110 1000 1001 di (decimal) 1 2 4 8 16 32 12 20 table 36-6. binary and decimal values for fi fi field 0000 0001 0010 0011 0100 0101 0110 1001 1010 1011 1100 1101 fi (decimal) 372 372 558 744 1116 1488 1860 512 768 1024 1536 2048 table 36-7. possible values for the fi/di ratio fi/di 372 558 744 1116 1488 1806 512 768 1024 1536 2048 1 372 558 744 1116 1488 1860 512 768 1024 1536 2048 2 186 279 372 558 744 930 256 384 512 768 1024 4 93 139.5 186 279 372 465 128 192 256 384 512 8 46.5 69.75 93 139.5 186 232.5 64 96 128 192 256 16 23.25 34.87 46.5 69.75 93 116.2 32 48 64 96 128 32 11.62 17.43 23.25 34.87 46.5 58.13 16 24 32 48 64 12 31 46.5 62 93 124 155 42.66 64 85.33 128 170.6 20 18.6 27.9 37.2 55.8 74.4 93 25.6 38.4 51.2 76.8 102.4
745 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-4 shows the relation between the elementary time unit, corresponding to a bit time, and the iso 7816 clock. figure 36-4. elementary time unit (etu) 36.6.2 receiver and transmitter control after reset, the receiver is disabled. the user must enable the receiver by setting the r xen bit in the control register (us_cr). however, the receiver registers can be programmed before the receiver clock is enabled. after reset, the transmitter is disabled. the user must enable it by setting the txen bit in the us_cr. however, the transmitter registers can be programmed before being enabled. the receiver and the transmitter can be enabled together or independently. at any time, the software can perform a reset on the receiver or the transmitter of the usart by setting the corresponding bit, rstrx and rsttx respectively, in the us_c r. the software resets clear the status flag and reset internal state machines but the user interface configuration registers hold the value configured prior to software reset. regardless of what the receiver or the transmitter is performing, the communication is immediately stopped. the user can also independently disable the receiver or the transmitter by setting rxdis and txdis respectively in the us_cr. if the receiver is disabled during a character reception, the usart waits until the end of reception of the current character, then the reception is stopped. if the transmitter is disabled while it is operating, the usart waits the end of transmission of both the current character and character be ing stored in the transmit hold ing register (us_thr). if a timeguard is programmed, it is handled normally. 36.6.3 synchronous and asynchronous modes 36.6.3.1 transmitter operations the transmitter performs the same in both synchronous and asynchronous operating modes (sync = 0 or sync = 1). one start bit, up to 9 data bits, one optional parity bit and up to two stop bits are successively shifted out on the txd pin at each falling edge of the programmed serial clock. the number of data bits is selected by the chrl field and the mode 9 bit in us_mr. nine bits are selected by setting the mode 9 bit regardless of the chrl field. the parity bit is set according to the par field in us_mr. the even, odd, space, marked or none parity bit can be configured. the msbf field in the us_mr configures which data bit is sent first. if written to 1, the most significant bit is sent first. if written to 0, the less significant bit is sent first. the number of stop bits is selected by the nbstop field in the us_mr. the 1.5 stop bit is supported in asynchronous mode only. figure 36-5. character transmit 1 etu iso7816 clock on sck iso7816 i/o line on txd fi_di_ratio iso7816 clock cycles d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit example: 8-bit, parity enabled one stop baud rate clock
746 sam4cp [datasheet] 43051e?atpl?08/14 the characters are sent by writing in the transmit holding register (us_thr). the transmitter reports two status bits in the channel status register (us_csr): txrdy (transmitter ready), which indicates that us_thr is empty and txempty, which indicates that all the characters written in us_thr have been processed. when the current character processing is completed, the last character written in us_thr is transferred into the shift register of the transmitter and us_thr becomes empty, thus txrdy rises. both txrdy and txempty bits are low when the transmitter is disabled. writing a character in us_thr while txrdy is low has no effect and the written character is lost. figure 36-6. transmitter status 36.6.3.2 manchester encoder when the manchester encoder is in use, characters transmitted through the usart are encoded based on biphase manchester ii format. to enable this mode, set the man bit in the us_mr to 1. depending on polarity configuration, a logic level (zero or one), is transmitted as a coded signal one-to-zero or zero-to-one. thus, a transition always occurs at the midpoint of each bit time. it consumes more bandwidth than the original nrz signal (2x) but the receiver has more error control since the expected input must show a change at the center of a bit cell. an example of manchester encoded sequence is: the byte 0xb1 or 10110001 encodes to 10 01 10 10 01 01 01 10, assuming the default polarity of the encoder. figure 36-7 illustrates this coding scheme. figure 36-7. nrz to manchester encoding the manchester encoded character can also be encapsulated by adding both a configurable preamble and a start frame delimiter pattern. depending on the configuration, the preamble is a training sequence, composed of a predefined pattern with a programmable length from 1 to 15 bit times. if the preamble length is set to 0, the preamble waveform is not generated prior to any character. the preamble pattern is chosen among the following sequences: all_one, all_zero, one_zero or zero_one, writing the field tx_pp in the us_man register, the field tx_pl is used to configure the preamble length. figure 36-8 illustrates and defines the valid patterns. to improve flexibility, the encoding scheme can be configured using the tx_mpol field in the us_man register. if the tx_mpol field is set to zero (default), a logic zero is encoded with a zero-to-one transition and a logic one is encoded with a one-to-zero transition. if the tx_mpol field is set to one, a logic one is encoded with a one-to-zero transition and a logic zero is encoded with a zero-to-one transition. d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock start bit write us_thr d0 d1 d2 d3 d4 d5 d6 d7 parity bit stop bit txrdy txempty nrz encoded data manchester encoded data 10110001 txd
747 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-8. preamble patterns, default polarity assumed a start frame delimiter is to be configured using the onebit bit in the us_mr. it consists of a user-defined pattern that indicates the beginning of a valid data. figure 36-9 illustrates these patterns. if the start frame delimiter, also known as the start bit, is one bit, (onebit to 1), a logic zero is ma nchester encoded and indicates that a new character is being sent serially on the line. if the start frame delimiter is a synchronization pattern also referred to as sync (onebit to 0), a sequence of three bit times is sent serial ly on the line to indicate the start of a new character. the sync waveform is in itself an invalid manchester waveform as the transition occurs at the middle of the second bit time. two distinct sync patterns are used: the command sync and the data sync. the command sync has a logic one level for one and a half bit times, then a transition to logic zero for the second one and a half bit times. if the modsync bit in the us_mr is set to 1, the next character is a command. if it is set to 0, the next character is a data. when direct memory access is used, the modsync field can be immediately updated with a modified character located in memory. to enable this mode, var_sync bit in us_mr must be set to 1. in this case, the modsync bit in the us_mr is bypassed and the sync configuration is held in the txsynh in the us_thr. the usart character format is modified and includes sync iinformation. figure 36-9. start frame delimiter m anchester encoded data txd sfd data 8 bit width all_one preamble m anchester encoded data txd sfd data 8 bit width all_zero preamble m anchester encoded data txd sfd data 8 bit width zero_one preamble m anchester encoded data txd sfd data 8 bit width one_zero preamble manchester encoded data txd sfd data one bit start frame delimiter preamble length is set to 0 manchester encoded data txd sfd data command sync start frame delimiter manchester encoded data txd sfd data data sync start frame delimiter
748 sam4cp [datasheet] 43051e?atpl?08/14 drift compensation drift compensation is available only in 16x oversampling mode. an hardware recovery system allows a larger clock drift. to enable the hardware system, the bit in the usart_man register must be set. if the rxd edge is one 16x clock cycle from the expected edge, this is considered as normal jitter and no corrective actions is taken. if the rxd event is between 4 and 2 clock cycles before the expected edge, then the current period is shortened by one clock cycle. if the rxd event is between 2 and 3 clock cycles after the expected edge, then the current period is lengthened by one clock cycle. these intervals are considered to be drift and so corrective actions are automatically taken. figure 36-10. bit resynchronization 36.6.3.3 asynchronous receiver if the usart is programmed in asynchronous operating mode (sync = 0), the receiver oversamples the rxd input line. the oversampling is either 16 or 8 times the baud rate clock, depending on the over bit in the us_mr. the receiver samples the rxd line. if the line is sampled during one half of a bit time to 0, a start bit is detected and data, parity and stop bits are successively sampled on the bit rate clock. if the oversampling is 16, (over to 0), a start is detected at the eighth sample to 0. data bits, parity bit and stop bit are assumed to have a duration corresponding to 16 oversampling clock cycles. if the oversampling is 8 (over to 1), a start bit is detected at the fourth sample to 0. data bits, parity bit and stop bit are assumed to have a duration corresponding to 8 oversampling clock cycles. the number of data bits, first bit sent and parity mode are selected by the same fields and bits as the transmitter, i.e., respectively chrl, mode9, msbf and par. for the synchronization mechanism only, the number of stop bits has no effect on the receiver as it considers only one stop bit, regardless of the field nbstop, so that resynchronization between the receiver and the transmitter can occur. moreover, as soon as the stop bit is sampled, the receiver starts looking for a new start bit so that resynchronization can also be accomplished when the transmitter is operating with one stop bit. rxd o versampling 16x clock sampling point expected edge tolerance synchro. jump sync jump synchro. error synchro. error
749 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-11 and figure 36-12 illustrate start detection and character reception when usart operates in asynchronous mode. figure 36-11. asynchronous start detection figure 36-12. asynchronous character reception 36.6.3.4 manchester decoder when the man bit in the us_mr is set to 1, the manchester decoder is enabled. the decoder performs both preamble and start frame delimiter detection. one input line is dedicated to manchester encoded input data. an optional preamble sequence can be defined, its length is user-defined and totally independent of the emitter side. use rx_pl in us_man register to configure the length of the preamble sequence. if the length is set to 0, no preamble is detected and the function is disabled. in addition, the polarity of the input stream is programmable with rx_mpol bit in us_man register. depending on the desired application the preamble pattern matching is to be defined via the rx_pp field in us_man. see figure 36-8 for available preamble patterns. unlike preamble, the start frame delimiter is shared between manchester encoder and decoder. so, if onebit field is set to 1, only a zero encoded manchester can be detected as a valid start frame delimiter. if onebit is set to 0, only a sync pattern is detected as a valid start frame delimiter. decoder operates by detecting transition on incoming stream. if rxd is sampled during one quarter of a bit time to zero, a start bit is detected. see figure 36-13 . the sample pulse rejection mechanism applies. the rxidlev bit in the us_man informs the usart of the receiver line idle state value (receiver line inactive). the user must define rxidlev to ensure reliable synchronization. by default, rxidlev is set to 1 (receiver line is at level 1 when there is no activity). sampling clock (x16) rxd start detection sampling baud rate clock rxd start rejection sampling 12345678 12345670 1234 12345678 9 10111213141516 d0 sampling d0 d1 d2 d3 d4 d5 d6 d7 rxd parity bit stop bit example: 8-bit, parity enabled baud rate clock start detection 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples 16 samples
750 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-13. asynchronous start bit detection the receiver is activated and starts preamble and frame delimiter detection, sampling the data at one quarter and then three quarters. if a valid preamble pattern or start frame delim iter is detected, the receiver continues decoding with the same synchronization. if the stream does not match a valid pattern or a valid start frame delimiter, the receiver resynchronizes on the next valid edge.the minimum time threshold to estimate the bit value is three quarters of a bit time. if a valid preamble (if used) followed with a valid start frame delimiter is detected, the inc oming stream is decoded into nrz data and passed to usart for processing. figure 36-14 illustrates manchester pattern mismatch. when incoming data stream is passed to the usart, the receiver is also able to detect manchester code violation. a code violation is a lack of transition in the middle of a bit cell. in this case, mane flag in the us_csr is raised. it is cleared by writing a 1 t o the rststa in the us_cr. see figure 36-15 for an example of manchester error detection during data phase. figure 36-14. preamble pattern mismatch figure 36-15. manchester error flag when the start frame delimiter is a sync pattern (onebit field to 0), both command and data delimiter are supported. if a valid sync is detected, the received character is written as rxchr field in the us_rhr and the rxsynh is updated. rxchr is set to 1 when the received character is a command, and it is set to 0 if the received character is a data. this mechanism alleviates and simplifies the direct memory access as the character contains its own sync field in the same register. as the decoder is setup to be used in unipolar mode, the first bit of the frame has to be a zero-to-one transition. manchester encoded data txd 1234 sampling clock (16 x) start detection manchester encoded data txd sfd data preamble length is set to 8 preamble mismatch invalid pattern preamble mismatch manchester coding error manchester encoded data txd sfd preamble length is set to 4 elementary character bit time manchester coding error detected sampling points preamble subpacket and start frame delimiter were successfully decoded entering usart character area
751 sam4cp [datasheet] 43051e?atpl?08/14 36.6.3.5 radio interface: manchester encoded usart application this section describes low data rate rf transmission systems and their integration with a manchester encoded usart. these systems are based on transmitter and receiver ics that support ask and fsk modulation schemes. the goal is to perform full duplex radio transmission of characters using two different frequency carriers. see the configuration in figure 36-16 . figure 36-16. manchester encoded characters rf transmission the usart peripheral is configured as a manchester encoder/decoder. looking at the downstream communication channel, manchester encoded characters are serially sent to the rf emitter. this may also include a user defined preamble and a start frame delimiter. mostly, preamble is used in the rf receiver to distinguish between a valid data from a transmitter and signals due to noise. the manchester stream is then modulated. see figure 36-17 for an example of ask modulation scheme. when a logic one is sent to the ask modulator, the power amplifier, referred to as pa, is enabled and transmits an rf signal at downstream frequency. when a logic zero is transmitted, the rf signal is turned off. if the fsk modulator is activated, two different frequencies are used to transmit data. when a logic 1 is sent, the modulator outputs an rf signal at frequency f0 and switches to f1 if the data sent is a 0. see figure 36-18 . from the receiver side, another carrier frequency is used. the rf receiver performs a bit check operation examining demodulated data stream. if a valid pattern is detected, the receiver switches to receiving mode. the demodulated stream is sent to the manchester decoder. because of bit checking inside rf ic, the data transferred to the microcontroller is reduced by a user-defined number of bits. the manchester preamble length is to be defined in accordance with the rf ic configuration. lna vco rf filter demod control bi-dir line pa rf filter mod vco control manchester decoder manchester encoder usart receiver usart emitter ask/fsk upstream receiver ask/fsk downstream transmitter upstream emitter downstream receiver serial configuration interface fup frequency carrier fdown frequency carrier
752 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-17. ask modulator output figure 36-18. fsk modulator output 36.6.3.6 synchronous receiver in synchronous mode (sync = 1), the receiver samples the rxd signal on each rising edge of the baud rate clock. if a low level is detected, it is considered as a start. all data bits, the parity bit and the stop bits are sampled and the receive r waits for the next start bit. synchronous mode operations provide a high speed transfer capability. configuration fields and bits are the same as in asynchronous mode. figure 36-19 illustrates a character reception in synchronous mode. figure 36-19. synchronous mode character reception 36.6.3.7 receiver operations when a character reception is completed, it is transferred to the receive holding register (us_rhr) and the rxrdy bit in us_csr rises. if a character is completed while the rxrdy is set, the ovre (overrun error) bit is set. the last character is transferred into us_rhr and overwrites the previous one. the ovre bit is cleared by writing a 1 to the rststa (reset status) bit in the us_cr. manchester encoded data default polarity unipolar output txd ask modulator output uptstream frequency f0 nrz stream 10 0 1 manchester encoded data default polarity unipolar output txd fsk modulator output uptstream frequencies [f0, f0+offset] nrz stream 10 0 1 d0 d1 d2 d3 d4 d5 d6 d7 rxd start sampling parity bit stop bit example: 8-bit, parity enabled 1 stop baud rate clock
753 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-20. receiver status 36.6.3.8 parity the usart supports five parity modes that are selected by writing to the par field in the us_mr. the par field also enables the multidrop mode, see ?multidrop mode? on page 754 . even and odd parity bit generation and error detection are supported. if even parity is selected, the parity generator of the transmitter drives the parity bit to 0 if a number of 1s in the charact er data bit is even, and to 1 if the number of 1s is odd. accordingly, the receiver parity checker counts the number of received 1s and reports a parity error if the sampled parity bit does not corr espond. if odd parity is selected, the parity generator of the transmitter drives the parity bit to 1 if a number of 1s in the character data bit is even, and to 0 if the number of 1s is odd. accordingly, the receiver parity checker counts the number of received 1s and reports a parity error if the sampled parity bit does not correspond. if the mark parity is used, the parity generator of the transmitter drives the parity bit to 1 for all characters. the receiver parity checker reports an error if the parity bit is sampled to 0. if the spac e parity is used, the parity generator of the transmitter drives the parity bit to 0 for all characters. the receiver parity checker reports an error if the parity bit is sampled to 1. if parity is disabled, the transmitter does not generate any parity bit and the receiver does not report any parity error. table 36-8 shows an example of the parity bit for the character 0x41 (character ascii ?a?) depending on the configuration of the usart. because there are two bits set to 1 in the character value, the parity bit is set to 1 when the parity is odd, or configured to 0 when the parity is even. when the receiver detects a parity error, it sets the pare (parity error) bit in the us_csr. the pare bit can be cleared by writing a 1 to the rststa bit in the us_cr. figure 36-21 illustrates the parity bit status setting and clearing. d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit parity bit stop bit baud rate clock write us_cr rxrdy ovre d0 d1 d2 d3 d4 d5 d6 d7 start bit parity bit stop bit rststa = 1 read us_rhr table 36-8. parity bit examples character hexadecimal binary parity bit parity mode a 0x41 0100 0001 1 odd a 0x41 0100 0001 0 even a 0x41 0100 0001 1 mark a 0x41 0100 0001 0 space a 0x41 0100 0001 none none
754 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-21. parity error 36.6.3.9 multidrop mode if the value 0x6 or 0x07 is written to the par field in the us_mr, the usart runs in multidrop mode. this mode differentiates the data characters and the address characters. data is transmitted with the parity bit at 0 and addresses are transmitted with the parity bit at 1. if the usart is configured in multidrop mode, the receiver sets the pare parity error bit when the parity bit is high and the transmitter is able to send a character with the parity bit high when a one is written to the senda bit in the us_cr. to handle parity error, the pare bit is cleared when a one is written to the rststa bit in the us_cr. the transmitter sends an address byte (parity bit set) when senda is written to in the us_cr. in this case, the next byte written to the us_thr is transmitted as an address. any character written in the us_thr without having written the command senda is transmitted normally with the parity at 0. 36.6.3.10 transmitter timeguard the timeguard feature enables the usart interface with slow remote devices. the timeguard function enables the transmitter to insert an idle state on the txd line between two characters. this idle state actually acts as a long stop bit. the duration of the idle state is programmed in the tg fi eld of the transmitter timeguard register (us_ttgr). when this field is written to zero no timeguard is generated. otherwise, the transmitter holds a high level on txd after each transmitted byte during the number of bit periods programmed in tg in addition to the number of stop bits. as illustrated in figure 36-22 , the behavior of txrdy and txempty status bits is modified by the programming of a timeguard. txrdy rises only when the start bit of the next character is sent, and thus remains to 0 during the timeguard transmission if a character has been written in us_thr. txempty remains low until the timeguard transmission is completed as the timeguard is part of the current character being transmitted. figure 36-22. timeguard operations d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit bad parity bit stop bit b aud rate clock write us_cr pare rxrdy rststa = 1 parity error detect time flags report time d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock start bit tg = 4 write us_thr d0 d1 d2 d3 d4 d5 d6 d7 parity bit stop bit txrdy txempty tg = 4
755 sam4cp [datasheet] 43051e?atpl?08/14 table 36-9 indicates the maximum length of a timeguard period that the transmitter can handle in relation to the function of the baud rate. 36.6.3.11 receiver time-out the receiver time-out provides support in handling variable-length frames. this feature detects an idle condition on the rxd line. when a time-out is detected, the bit timeout in the us_csr rises and can generate an interrupt, thus indicating to the driver an end of frame. the time-out delay period (during which the receiver waits for a new character) is programmed in the to field of the receiver time-out register (us_rtor). if the to field is written to 0, the receiver time-out is disabled and no time-out is detected. the timeout bit in the us_csr remains at 0. otherwise, the receiver loads a 16-bit counter with the value programmed in to. this counter is decremented at each bit period and reloaded each time a new character is received. if the counter reaches 0, the timeout bit in us_csr rises. then, the user can either: ? stop the counter clock until a new character is received. this is performed by writing a one to the sttto (start time-out) bit in the us_cr. in this case, the idle state on rxd before a new character is received will not provide a time-out. this prevents having to handle an interrupt before a character is received and allows waiting for the next idle state on rxd after a frame is received. ? obtain an interrupt while no character is received. this is performed by writing a one to the retto (reload and start time-out) bit in the us_cr. if retto is performed, the counter starts counting down immediately from the value to. this enables generation of a periodic interrupt so that a user time-out can be handled, for example when no key is pressed on a keyboard. if sttto is performed, the counter clock is stopped until a first character is received. the idle state on rxd before the start of the frame does not provide a time-out. this prevents hav ing to obtain a periodic interrupt and enables a wait of the end of frame when the idle state on rxd is detected. if retto is performed, the counter star ts counting down immediately from th e value to. this enables generation of a periodic interrupt so that a user time-out can be handled, for example when no key is pressed on a keyboard. figure 36-23 shows the block diagram of the receiver time-out feature. table 36-9. maximum timeguard length depending on baud rate baud rate (bit/s) bit time ( s) timeguard (ms) 1 200 833 212.50 9 600 104 26.56 14400 69.4 17.71 19200 52.1 13.28 28800 34.7 8.85 38400 26 6.63 56000 17.9 4.55 57600 17.4 4.43 115200 8.7 2.21
756 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-23. receiver time-out block diagram table 36-10 gives the maximum time-out period for some standard baud rates. 36.6.3.12 framing error the receiver is capable of detecting framing errors. a framing error happens when the stop bit of a received character is detected at level 0. this can occur if the receiver and the transmitter are fully desynchronized. a framing error is reported on the frame bit of the us_csr. the frame bit is asserted in the middle of the stop bit as soon as the framing error is detected. it is cleared by writing a 1 to the rststa in the us_cr. figure 36-24. framing error status table 36-10. maximum time-out period baud rate (bit/s) bit time ( s) time-out (ms) 600 1 667 109 225 1 200 833 54 613 2 400 417 27 306 4 800 208 13 653 9 600 104 6 827 14400 69 4 551 19200 52 3 413 28800 35 2 276 38400 26 1 704 56000 18 1 170 57600 17 1 138 200000 5 328 16-bit time-out counter 0 to timeout baud rate clock = character received retto load clock 16-bit value sttto dq 1 clear d0 d1 d2 d3 d4 d5 d6 d7 rxd start bit parity bit stop bit baud rate clock write us_cr frame rxrdy rststa = 1
757 sam4cp [datasheet] 43051e?atpl?08/14 36.6.3.13 transmit break the user can request the transmitter to generate a break condition on the txd line. a break condition drives the txd line low during at least one complete character. it appears the same as a 0x00 character sent with the parity and the stop bits at 0. however, the transmitter holds the txd line at least during one character until the user requests the break condition to be removed. a break is transmitted by writing a 1 to the sttbrk bit in the us_cr. this can be performed at any time, either while the transmitter is empty (no character in either the shift register or in us_thr) or when a character is being transmitted. if a break is requested while a character is being shifted out, the character is first completed before the txd line is held low. once sttbrk command is requested further sttbrk commands are ignored until the end of the break is completed. the break condition is removed by writing a 1 to the stpbrk bit in the us_cr. if the stpbrk is requested before the end of the minimum break duration (one character, including start, data, parity and stop bits), the transmitter ensures that the break condition completes. the transmitter considers the break as though it is a character, i.e., the sttbrk and stpbrk commands are taken into account only if the txrdy bit in us_csr is to 1 and the start of the break condition clears the txrdy and txempty bits as if a character is processed. writing us_cr with both sttbrk and stpbrk bits to 1 can lead to an unpredictable result. all stpbrk commands requested without a previous sttbrk command are ignored. a byte written into the transmit holding register while a break is pending, but not started, is ignored. after the break condition, the transmitter returns the txd line to 1 for a minimum of 12 bit times. thus, the transmitter ensures that the remote receiver detects correctly the end of break and the start of the next character. if the timeguard is programmed with a value higher than 12, the txd line is held high for the timeguard period. after holding the txd line for this period, the transmitter resumes normal operations. figure 36-25 illustrates the effect of both the start break (sttbrk) and stop break (stpbrk) commands on the txd line. figure 36-25. break transmission 36.6.3.14 receive break the receiver detects a break condition when all data, parity and stop bits are low. this corresponds to detecting a framing error with data to 0x00, but frame remains low. when the low stop bit is detected, the receiver asserts the rxbrk bit in us_csr. this bit may be cleared by writing a 1 to the rststa bit in the us_cr. an end of receive break is detected by a high level for at least 2/16 of a bit period in asynchronous operating mode or one sample at high level in synchronous operating mode. the end of break detection also asserts the rxbrk bit. d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock write us_cr txrdy txempty stpbrk = 1 sttbrk = 1 break transmission end of break
758 sam4cp [datasheet] 43051e?atpl?08/14 36.6.3.15 hardware handshaking the usart features a hardware handshaking out-of-band flow control. the rts and cts pins are used to connect with the remote device, as shown in figure 36-26 . figure 36-26. connection with a remote device for hardware handshaking setting the usart to operate with hardware handshaking is performed by writing the usart_mode field in us_mr to the value 0x2. the usart behavior when hardware handshaking is enabled is the same as the behavior in standard synchronous or asynchronous mode, except that the receiver drives the rts pin as described below and the level on the cts pin modifies the behavior of the transmitter as described below. using this mode requires using the pdc channel for reception. the transmitter can handle hardware handshaking in any case. figure 36-27 shows how the receiver operates if hardware handshaking is enabled. the rts pin is driven high if the receiver is disabled and if the status rxbuff (receive buffer full) coming from the pdc channel is high. normally, the remote device does not start transmitting while its cts pin (driven by rts) is high. as soon as the receiver is enabled, the rts falls, indicating to the remote device that it can star t transmitting. defining a new buffer to the pdc clears the status bit rxbuff and, as a result, asserts the pin rts low. figure 36-27. receiver behavior when operating with hardware handshaking figure 36-28 shows how the transmitter operates if hardware handshaking is enabled. the cts pin disables the transmitter. if a character is being processing, the transmitter is disabled only after the completion of the current character and transmission of the next character happens as soon as the pin cts falls. figure 36-28. transmitter behavior when operating with hardware handshaking usart txd cts remote device rxd txd rxd rts rts cts rts rxbuff write us_cr rxen = 1 rxd rxdis = 1 cts txd
759 sam4cp [datasheet] 43051e?atpl?08/14 36.6.4 iso7816 mode the usart features an iso7816-compatible operating mode. this mode permits interfacing with smart cards and security access modules (sam) communicating through an iso7816 link. both t = 0 and t = 1 protocols defined by the iso7816 specification are supported. setting the usart in iso7816 mode is performed by writing the usart_mode field in us_mr to the value 0x4 for protocol t = 0 and to the value 0x5 for protocol t = 1. 36.6.4.1 iso7816 mode overview the iso7816 is a half duplex communication on only one bidirectional line. the baud rate is determined by a division of the clock provided to the remote device (see ?baud rate generator? on page 741 ). the usart connects to a smart card as shown in figure 36-29 . the txd line becomes bidirectional and the baud rate generator feeds the iso7816 clock on the sck pin. as the txd pin becomes bidirectional, its output remains driven by the output of the transmitter but only when the transmitter is active while its input is directed to the input of the receiver. the usart is considered as the master of the communication as it generates the clock. figure 36-29. connection of a smart card to the usart when operating in iso7816, either in t = 0 or t = 1 modes, the character format is fixed. the configuration is 8 data bits, even parity and 1 or 2 stop bits, regardless of the values programmed in the chrl, mode9, par and chmode fields. msbf can be used to transmit lsb or msb first. parity bit (par) can be used to transmit in normal or inverse mode. refer to ?usart mode register? on page 774 and ?par: parity type? on page 775 . the usart cannot operate concurrently in both receiver and transmitter modes as the communication is unidirectional at a time. it has to be configured according to the required mode by enabling or disabling either the receiver or the transmitter as desired. enabling both the receiver and the transmitter at the same time in iso7816 mode may lead to unpredictable results. the iso7816 specification defines an inverse transmission format. data bits of the character must be transmitted on the i/o line at their negative value. 36.6.4.2 protocol t = 0 in t = 0 protocol, a character is made up of one start bit, eight data bits, one parity bit and one guard time, which lasts two bit times. the transmitter shifts out the bits and does not drive the i/o line during the guard time. if no parity error is detected, the i/o line remains at 1 during the guard time and the transmitter can continue with the transmission of the next character, as shown in figure 36-30 . if a parity error is detected by the receiver, it drives the i/o line to 0 during the guard time, as shown in figure 36-31 . this error bit is also named nack, for non acknowledge. in this case, the character lasts 1 bit time more, as the guard time length is the same and is added to the error bit time which lasts 1 bit time. when the usart is the receiver and it detects an error, it does not load the erroneous character in the receive holding register (us_rhr). it appropriately sets the pare bit in the status register (us_sr) so that the software can handle the error. smart card sck clk txd i/o usart
760 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-30. t = 0 protocol without parity error figure 36-31. t = 0 protocol with parity error receive error counter the usart receiver also records the total number of errors. this can be read in the number of error (us_ner) register. the nb_errors field can record up to 255 errors. reading us_ner automatically clears the nb_errors field. receive nack inhibit the usart can also be configured to inhibit an error. this can be achieved by setting the inack bit in us_mr. if inack is to 1, no error signal is driven on the i/o line even if a parity bit is detected. moreover, if inack is set, the erroneous received character is stored in the receive holding register, as if no error occurred and the rxrdy bit does rise. transmit character repetition when the usart is transmitting a character and gets a nack, it can automatically repeat the character before moving on to the next one. repetition is enabled by writing the ma x_iteration field in the us_m r at a value higher than 0. each character can be transmitted up to eight times; the first transmission plus seven repetitions. if max_iteration does not equal zero, the usart repeats the character as many times as the value loaded in max_iteration. when the usart repetition number reaches max_iteration and the last repeated character is not acknowledge, the iter bit is set in the us_csr. if the repetition of the character is acknowledged by the receiver, the repetitions are stopped and the iteration counter is cleared. the iter bit in us_csr can be cleared by writing a 1 to the rstit bit in the us_cr. disable successive receive nack the receiver can limit the number of successive nacks sent back to the remote transmitter. this is programmed by setting the bit dsnack in the us_mr. the maximum number of nacks transmitted is programmed in the max_iteration field. as soon as max_iteration is reached,no error signal is driven on the i/o line and the iter bit in the us_csr is set. 36.6.4.3 protocol t = 1 when operating in iso7816 protocol t = 1, the transmission is similar to an asynchronous format with only one stop bit. the parity is generated when transmitti ng and checked when receiving. parity error detection sets the pare bit in the us_csr. d0 d1 d2 d3 d4 d5 d6 d7 rxd parity bit baud rate clock start bit guard time 1 next start bit guard time 2 d0 d1 d2 d3 d4 d5 d6 d7 i/o parity bit baud rate clock start bit guard time 1 start bit guard time 2 d0 d 1 error repetition
761 sam4cp [datasheet] 43051e?atpl?08/14 36.6.5 irda mode the usart features an irda mode supplying half-duplex point-to-point wireless communication. it embeds the modulator and demodulator which allows a glueless conn ection to the infrared transceivers, as shown in figure 36-32 . the modulator and demodulator are compliant with the irda specification version 1.1 and support data transfer speeds ranging from 2.4 kb/s to 115.2 kb/s. the irda mode is enabled by setting the usart_mode field in us_mr to the value 0x8. the irda filter register (us_if) is used to configure the demodulator filter. the usart transmitter and receiver operate in a normal asynchronous mode and all parameters are accessible. note that the modulator and the demodulator are activated. figure 36-32. connection to irda transceivers the receiver and the transmitter must be enabled or disabled depending on the direction of the transmission to be managed. to receive irda signals, the following needs to be done: ? disable tx and enable rx. ? configure the txd pin as pio and set it as an output to 0 (to avoid led emission). disable the internal pull-up (better for power consumption). ? receive data. 36.6.5.1 irda modulation for baud rates up to and including 115.2 kb/s, the rzi modulation scheme is used. ?0? is represented by a light pulse of 3/16th of a bit time. some examples of signal pulse duration are shown in table 36-11 . irda transceivers rxd rx txd tx usart demodulator modulator receiver transmitter table 36-11. irda pulse duration baud rate pulse duration (3/16) 2.4 kb/s 78.13 s 9.6 kb/s 19.53 s 19.2 kb/s 9.77 s 38.4 kb/s 4.88 s 57.6 kb/s 3.26 s 115.2 kb/s 1.63 s
762 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-33 shows an example of character transmission. figure 36-33. irda modulation 36.6.5.2 irda baud rate table 36-12 gives some examples of cd values, baud rate error and pulse duration. note that the requirement on the maximum acceptable error of 1.87% must be met. bit period bit period 3 16 start bit data bits stop bit 0 0 0 0 0 1 1 1 1 1 transmitter output txd table 36-12. irda baud rate error peripheral clock baud rate (bit/s) cd baud rate error pulse time ( s) 3 686 400 115 200 2 0.00% 1.63 20 000 000 115 200 11 1.38% 1.63 32 768 000 115 200 18 1.25% 1.63 40 000 000 115 200 22 1.38% 1.63 3 686 400 57 600 4 0.00% 3.26 20 000 000 57 600 22 1.38% 3.26 32 768 000 57 600 36 1.25% 3.26 40 000 000 57 600 43 0.93% 3.26 3 686 400 38 400 6 0.00% 4.88 20 000 000 38 400 33 1.38% 4.88 32 768 000 38 400 53 0.63% 4.88 40 000 000 38 400 65 0.16% 4.88 3 686 400 19 200 12 0.00% 9.77 20 000 000 19 200 65 0.16% 9.77 32 768 000 19 200 107 0.31% 9.77 40 000 000 19 200 130 0.16% 9.77 3 686 400 9 600 24 0.00% 19.53 20 000 000 9 600 130 0.16% 19.53 32 768 000 9 600 213 0.16% 19.53 40 000 000 9 600 260 0.16% 19.53 3 686 400 2 400 96 0.00% 78.13 20 000 000 2 400 521 0.03% 78.13 32 768 000 2 400 853 0.04% 78.13
763 sam4cp [datasheet] 43051e?atpl?08/14 36.6.5.3 irda demodulator the demodulator is based on the irda receive filter comprised of an 8-bit down counter which is loaded with the value programmed in us_if. when a fall ing edge is detected on the rxd pin, the filter counter starts counting down at the peripheral clock speed. if a rising edge is detected on the rxd pin, the counter stops and is reloaded with us_if. if no rising edge is detected when the counter reaches 0, the input of the receiver is driven low during one bit time. figure 36-34 illustrates the operations of the irda demodulator. figure 36-34. irda demodulator operations the programmed value in the us_if register must always meet the following criteria: t peripheral clock * (irda_filter + 3) < 1.41 s as the irda mode uses the same logic as the iso7816, note that the fi_di_ratio field in us_fidi must be set to a value higher than 0 in order to assure irda communications operate correctly. 36.6.6 rs485 mode the usart features the rs485 mode to enable line driver control. while operating in rs485 mode, the usart behaves as though in asynchronous or synchronous mode and configuration of all the parameters is possible. the difference is that the rts pin is driven high when the transmitter is operating. the behavior of the rts pin is controlled by the txempty bit. a typical connection of the usart to an rs485 bus is shown in figure 36-35 . figure 36-35. typical connection to a rs485 bus the usart is set in rs485 mode by writing the value 0x1 to the usart_mode field in us_mr. the rts pin is at a level inverse to the txempty bit. significantly, the rts pin remains high when a timeguard is programmed so that the line can remain driven after the last character completion. figure 36-36 gives an example of the rts waveform during a character transmission when the timeguard is enabled. p eripheral clock rxd receiver input pulse rejected 65432 6 1 65432 0 pulse accepted counter value usart rts txd rxd differential bus
764 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-36. example of rts drive with timeguard 36.6.7 spi mode the serial peripheral interface (spi) mode is a synchronous s erial data link that provides communication with external devices in master or slave mode. it also enables communication between processors if an external processor is connected to the system. the serial peripheral interface is essentially a shift register that serially transmits data bits to other spis. during a data transfer, one spi system acts as the ?master? which controls the data flow, while the other devices act as ?slaves'' which have data shifted into and out by the master. different cpus can take turns being masters and one master may simultaneously shift data into multiple slaves. (multiple master protocol is the opposite of single master protocol, where one cpu is always the master while all of the others are always slaves.) however, only one slave may drive its output to write data back to the master at any given time. a slave device is selected when its nss signal is asserted by the master. the usart in spi master mode can address only one spi slave because it can generate only one nss signal. the spi system consists of two data lines and two control lines: ? master out slave in (mosi): this data line supplies the output data from the master shifted into the input of the slave. ? master in slave out (miso): this data line supplies the output data from a slave to the input of the master. ? serial clock (sck): this control line is driven by the master and regulates the flow of the data bits. the master may transmit data at a variety of baud rates. the sck line cycles once for each bit that is transmitted. ? slave select (nss): this control line allows the master to select or deselect the slave. 36.6.7.1 modes of operation the usart can operate in spi master mode or in spi slave mode. operation in spi master mode is programmed by writing 0xe to the usart_mode field in us_mr. in this case the spi lines must be connected as described below: ? the mosi line is driven by the output pin txd. ? the miso line drives the input pin rxd. ? the sck line is driven by the output pin sck. ? the nss line is driven by the output pin rts. operation in spi slave mode is programmed by writing 0xf to the usart_mode field in us_mr. in this case the spi lines must be connected as described below: ? the mosi line drives the input pin rxd. ? the miso line is driven by the output pin txd. d0 d1 d2 d3 d4 d5 d6 d7 txd start bit parity bit stop bit baud rate clock tg = 4 write us_thr txrdy txempty rts 1
765 sam4cp [datasheet] 43051e?atpl?08/14 ? the sck line drives the input pin sck. ? the nss line drives the input pin cts. in order to avoid unpredictable behavior, any change of the spi mode must be followed by a software reset of the transmitter and of the receiver (except the initial configuration after a hardware reset). see section 36.6.7.4 . 36.6.7.2 baud rate in spi mode, the baud rate generator operates in the same way as in usart synchronous mode: see ?baud rate in synchronous mode or spi mode? on page 743. however, there are some restrictions: in spi master mode: ? the external clock sck must not be selected (usclks ? 0x3), and the bit clko must be set to 1 in the us_mr, in order to generate correctly the serial clock on the sck pin. ? to obtain correct behavior of the receiver and the transmitter, the value programmed in cd must be superior or equal to 6. ? if the divided peripheral clock is selected, the value programmed in cd must be even to ensure a 50:50 mark/space ratio on the sck pin, this value can be odd if the peripheral clock is selected. in spi slave mode: ? the external clock (sck) selection is forced regardless of the value of the usclks field in the us_mr. likewise, the value written in us_brgr has no effect, because the clock is provided directly by the signal on the usart sck pin. ? to obtain correct behavior of the receiver and the transmitter, the external clock (sck) frequency must be at least 6 times lower than the system clock. 36.6.7.3 data transfer up to nine data bits are successively shifted out on the txd pin at each rising or falling edge (depending of cpol and cpha) of the programmed serial clock. there is no start bit, no parity bit and no stop bit. the number of data bits is selected by the chrl field and the mode 9 bit in the us_mr. the nine bits are selected by setting the mode 9 bit regardless of the chrl field. the msb data bit is always sent first in spi mode (master or slave). four combinations of polarity and phase are available for data transfers. the clock polarity is programmed with the cpol bit in the us_mr. the clock phase is programmed with the cpha bit. these two parameters determine the edges of the clock signal upon which data is driven and sampled. each of the two parameters has two possible states, resulting in four possible combinations that are incompatible with one another. thus, a master/slave pair must use the same parameter pair values to communicate. if multiple slaves are used and fixed in different configurations, the master must reconfigure itself each time it needs to communicate with a different slave. table 36-13. spi bus protocol mode spi bus protocol mode cpol cpha 001 100 211 310
766 sam4cp [datasheet] 43051e?atpl?08/14 figure 36-37. spi transfer format (cpha=1, 8 bits per transfer) figure 36-38. spi transfer format (cpha=0, 8 bits per transfer) 6 sck (cpol = 0) sck (cpol = 1) mosi spi master ->txd spi slave -> rxd nss spi master -> rts spi slave -> cts sck cycle (for reference) msb msb lsb lsb 6 6 5 5 4 4 3 3 2 2 1 1 1 2345 78 6 miso spi master ->rxd spi slave -> txd sck (cpol = 0) sck (cpol = 1) 1 2345 7 mosi spi master -> txd spi slave -> rxd miso spi master -> rxd spi slave -> txd nss spi master -> rts spi slave -> cts sck cycle (for reference) 8 msb msb lsb lsb 6 6 5 5 4 4 3 3 1 1 2 2 6
767 sam4cp [datasheet] 43051e?atpl?08/14 36.6.7.4 receiver and transmitter control see ?receiver and transmitter control? on page 745. 36.6.7.5 character transmission the characters are sent by writing in the transmit holding register (us_thr). an additional condition for transmitting a character can be added when the usart is configured in spi master mode. in the ?usart mode register (spi_mode)? (usart_mr), the value configured on the bit wrdbt can prevent any character transmission (even if us_thr has been written) while the receiver side is not ready (character not read). when wrdbt equals 0, the character is transmitted whatever the receiver status. if wrdbt is set to 1, the transmitter waits for the receive holding register (us_rhr) to be read before transmitting the character (rxrdy flag cleared), thus preventing any overflow (character loss) on the receiver side. the transmitter reports two status bits in us_csr: txrdy (transmitter ready), which indicates that us_thr is empty and txempty, which indicates that all the characters written in us_thr have been processed. when the current character processing is completed, the last character written in us_thr is transferred into the shift register of the transmitter and us_thr becomes empty, thus txrdy rises. both txrdy and txempty bits are low when the transmitter is disabled. writing a character in us_thr while txrdy is low has no effect and the written character is lost. if the usart is in spi slave mode and if a character must be sent while the us_thr is empty, the unre (underrun error) bit is set. the txd transmission line stays at high le vel during all this time. the unre bit is cleared by writing a one to the rststa (reset status) bit in us_cr. in spi master mode, the slave select line (nss) is asserted at low level 1 t bit (t bit being the nominal time required to transmit a bit) before the transmission of the msb bit and released at high level 1 t bit after the transmission of the lsb bit. so, the slave select line (nss) is always released between each character transmission and a minimum delay of 3 t bits always inserted. however, in order to address slave devices supporting the csaat mode (chip select active after transfer), the slave select line (nss) can be forced at low level by writing a one to the rtsen bit in the us_cr. the slave select line (nss) can be released at high level only by writing a one to the rtsdis bit in the us_cr (for example, when all data have been transferred to the slave device). in spi slave mode, the transmitter does not require a falling edge of the slave select line (nss) to initiate a character transmission but only a low level. however, this low level must be present on the slave select line (nss) at least 1 t bit before the first serial clock cycle corresponding to the msb bit. 36.6.7.6 character reception when a character reception is completed, it is transferred to the receive holding register (us_rhr) and the rxrdy bit in the status register (us_csr) rises. if a character is completed while rxrdy is set, the ovre (overrun error) bit is set. the last character is transferred into us_rhr and overwrites the previous one. the ovre bit is cleared by writing a one to the rststa (reset status) bit in the us_cr. to ensure correct behavior of the receiver in spi slave mode, the master device sending the frame must ensure a minimum delay of 1 t bit between each character transmission. the rece iver does not require a falling edge of the slave select line (nss) to initiate a character reception but only a low level. however, this low level must be present on the slave select line (nss) at least 1 t bit before the first serial clock cycle corresponding to the msb bit. 36.6.7.7 receiver timeout because the receiver baud rate clock is active only during data transfers in spi mode, a receiver timeout is impossible in this mode, whatever the time-out value is (field to) in the us_rtor. 36.6.8 test modes the usart can be programmed to operate in three different test modes. the internal loopback capability allows on-board diagnostics. in loopback mode, the usart interface pins are disconnected or not and reconfigured for loopback internally or externally.
768 sam4cp [datasheet] 43051e?atpl?08/14 36.6.8.1 normal mode normal mode connects the rxd pin on the receiver input and the transmitter output on the txd pin. figure 36-39. normal mode configuration 36.6.8.2 automatic echo mode automatic echo mode allows bit-by-bit retransmission. when a bit is received on the rxd pin, it is sent to the txd pin, as shown in figure 36-40 . programming the transmitter has no effect on the txd pin. the rxd pin is still connected to the receiver input, thus the receiver remains active. figure 36-40. automatic echo mode configuration 36.6.8.3 local loopback mode local loopback mode connects the output of the transmitter directly to the input of the receiver, as shown in figure 36-41 . the txd and rxd pins are not used. the rxd pin has no effect on the receiver and the txd pin is continuously driven high, as in idle state. figure 36-41. local loopback mode configuration 36.6.8.4 remote loopback mode remote loopback mode directly connects the rxd pin to the txd pin, as shown in figure 36-42 . the transmitter and the receiver are disabled and have no effect. this mode allows bit-by-bit retransmission. figure 36-42. remote loopback mode configuration receiver transmitter rxd txd receiver transmitter rxd txd receiver transmitter rxd txd 1 receiver transmitter rxd txd 1
769 sam4cp [datasheet] 43051e?atpl?08/14 36.6.9 register write protection to prevent any single software error from corrupting usart behavior, certain registers in the address space can be write-protected by setting the wpen bit in the ?usart write protection mode register? (us_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the ?usart write protection status register? (us_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the us_wpsr. the following registers can be write-protected: ? ?usart mode register? ? ?usart baud rate generator register? ? ?usart receiver time-out register? ? ?usart transmitter timeguard register? ? ?usart fi di ratio register? ? ?usart irda filter register? ? ?usart manchester configuration register? 36.7 universal synchronous asynchronous receiver transmitter (usart) user interface table 36-14. register mapping offset register name access reset 0x0000 control register us_cr write-only ? 0x0004 mode register us_mr read/write ? 0x0008 interrupt enable register us_ier write-only ? 0x000c interrupt disable register us_idr write-only ? 0x0010 interrupt mask register us_imr read-only 0x0 0x0014 channel status register us_csr read-only ? 0x0018 receive holding register us_rhr read-only 0x0 0x001c transmit holding register us_thr write-only ? 0x0020 baud rate generator register us_brgr read/write 0x0 0x0024 receiver time-out register us_rtor read/write 0x0 0x0028 transmitter timeguard register us_ttgr read/write 0x0 0x2c - 0x3c reserved ? ? ? 0x0040 fi di ratio register us_fidi read/write 0x174 0x0044 number of errors register us_ner read-only ? 0x0048 reserved ? ? ? 0x004c irda filter register us_if read/write 0x0 0x0050 manchester configuration register us_man read/write 0x30011004 0x0054 - 0x005c reserved ? ? ? 0x0060 - 0x00e0 reserved ? ? ? 0x00e4 write protection mode register us_wpmr read/write 0x0 0x00e8 write protection status register us_wpsr read-only 0x0 0x00ec - 0x00fc reserved ? ? ? 0x100 - 0x128 reserved for pdc registers ? ? ?
770 sam4cp [datasheet] 43051e?atpl?08/14 36.7.1 usart control register name: us_cr address: 0x40024000 (0), 0x40028000 (1), 0x4002c000 (2), 0x40030000 (3), 0x40034000 (4) access: write-only for spi control, see ?usart control register (spi_mode)? on page 772 . ? rstrx: reset receiver 0: no effect. 1: resets the receiver. ? rsttx: reset transmitter 0: no effect. 1: resets the transmitter. ? rxen: receiver enable 0: no effect. 1: enables the receiver, if rxdis is 0. ? rxdis: receiver disable 0: no effect. 1: disables the receiver. ? txen: transmitter enable 0: no effect. 1: enables the transmitter if txdis is 0. ? txdis: transmitter disable 0: no effect. 1: disables the transmitter. ? rststa: reset status bits 0: no effect. 1: resets the status bits pare, frame, ovre, manerr and rxbrk in us_csr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? rtsdis rtsen ? ? 15 14 13 12 11 10 9 8 retto rstnack rstit senda sttto stpbrk sttbrk rststa 76543210 txdis txen rxdis rxen rsttx rstrx ? ?
771 sam4cp [datasheet] 43051e?atpl?08/14 ? sttbrk: start break 0: no effect. 1: starts transmission of a break after the characters present in us_thr and the transmit shift register have been transmitted. no effect if a break is already being transmitted. ? stpbrk: stop break 0: no effect. 1: stops transmission of the break after a minimum of one charac ter length and transmits a high level during 12-bit periods. no effect if no break is being transmitted. ? sttto: start time-out 0: no effect. 1: starts waiting for a character before clocking the time-out counter. resets the status bit timeout in us_csr. ? senda: send address 0: no effect. 1: in multidrop mode only, the next character written to the us_thr is sent with the address bit set. ? rstit: reset iterations 0: no effect. 1: resets iteration in us_csr. no effect if the iso7816 is not enabled. ? rstnack: reset non acknowledge 0: no effect. 1: resets nack in us_csr. ? retto: rearm time-out 0: no effect. 1: restart time-out. ? rtsen: request to send enable 0: no effect. 1: drives the pin rts to 0. ? rtsdis: request to send disable 0: no effect. 1: drives the pin rts to 1.
772 sam4cp [datasheet] 43051e?atpl?08/14 36.7.2 usart control register (spi_mode) name: us_cr (spi_mode) address: 0x40024000 (0), 0x40028000 (1), 0x4002c000 (2), 0x40030000 (3), 0x40034000 (4) access: write-only this configuration is relevant only if usart_mode=0xe or 0xf in the ?usart mode register? on page 774 . ? rstrx: reset receiver 0: no effect. 1: resets the receiver. ? rsttx: reset transmitter 0: no effect. 1: resets the transmitter. ? rxen: receiver enable 0: no effect. 1: enables the receiver, if rxdis is 0. ? rxdis: receiver disable 0: no effect. 1: disables the receiver. ? txen: transmitter enable 0: no effect. 1: enables the transmitter if txdis is 0. ? txdis: transmitter disable 0: no effect. 1: disables the transmitter. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? rcs fcs ? ? 15 14 13 12 11 10 9 8 ??????? rststa 76543210 txdis txen rxdis rxen rsttx rstrx ? ?
773 sam4cp [datasheet] 43051e?atpl?08/14 ? rststa: reset status bits 0: no effect. 1: resets the status bits ovre, unre in us_csr. ? fcs: force spi chip select applicable if usart operates in spi master mode (usart_mode = 0xe): 0: no effect. 1: forces the slave select line nss (rts pin) to 0, even if usart is not transmitting, in order to address spi slave devices supporting the csaat mode (chip select active after transfer). ? rcs: release spi chip select applicable if usart operates in spi master mode (usart_mode = 0xe): 0: no effect. 1: releases the slave select line nss (rts pin).
774 sam4cp [datasheet] 43051e?atpl?08/14 36.7.3 usart mode register name: us_mr address: 0x40024004 (0), 0x40028004 (1), 0x4002c004 (2), 0x40030004 (3), 0x40034004 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? on page 798 . for spi configuration, see ?usart mode register (spi_mode)? on page 777 . ? usart_mode: usart mode of operation the pdc transfers are supported in all usart modes of operation. ? usclks: clock selection ? chrl: character length 31 30 29 28 27 26 25 24 onebit modsync man filter ? max_iteration 23 22 21 20 19 18 17 16 invdata var_sync dsnack inack over clko mode9 msbf 15 14 13 12 11 10 9 8 chmode nbstop par sync 76543210 chrl usclks usart_mode value name description 0x0 normal normal mode 0x1 rs485 rs485 0x2 hw_handshaking hardware handshaking 0x4 is07816_t_0 is07816 protocol: t = 0 0x6 is07816_t_1 is07816 protocol: t = 1 0x8 irda irda 0xe spi_master spi master 0xf spi_slave spi slave value name description 0 mck peripheral clock is selected 1 div peripheral clock divided (div=8) is selected 3 sck serial clock slk is selected value name description 0 5_bit character length is 5 bits 1 6_bit character length is 6 bits 2 7_bit character length is 7 bits 3 8_bit character length is 8 bits
775 sam4cp [datasheet] 43051e?atpl?08/14 ? sync: synchronous mode select 0: usart operates in asynchronous mode. 1: usart operates in synchronous mode. ? par: parity type ? nbstop: number of stop bits ? chmode: channel mode ? msbf: bit order 0: least significant bit is sent/received first. 1: most significant bit is sent/received first. ? mode9: 9-bit character length 0: chrl defines character length. 1: 9-bit character length. ? clko: clock output select 0: the usart does not drive the sck pin. 1: the usart drives the sck pin if usclks does not select the external clock sck. ? over: oversampling mode 0: 16x oversampling. 1: 8x oversampling. value name description 0 even even parity 1 odd odd parity 2 space parity forced to 0 (space) 3 mark parity forced to 1 (mark) 4 no no parity 6 multidrop multidrop mode value name description 0 1_bit 1 stop bit 1 1_5_bit 1.5 stop bit (sync = 0) or reserved (sync = 1) 2 2_bit 2 stop bits value name description 0 normal normal mode 1 automatic automatic echo. receiver input is connected to the txd pin 2 local_loopback local loopback. transmitter output is connected to the receiver input 3 remote_loopback remote loopback. rxd pin is internally connected to the txd pin
776 sam4cp [datasheet] 43051e?atpl?08/14 ? inack: inhibit non acknowledge 0: the nack is generated. 1: the nack is not generated. ? dsnack: disable successive nack 0: nack is sent on the iso line as soon as a parity error occurs in the received character (unless inack is set). 1: successive parity errors are counted up to the value specified in the max_iteration field. these parity errors generate a nack on the iso line. as soon as this value is reached, no additional nack is sent on the iso line. the flag iteration is asserted. note: max_iteration field must be set to 0 if dsnack is cleared. ? invdata: inverted data 0: the data field transmitted on txd line is the same as the one written in us_thr or the content read in us_rhr is the same as rxd line. normal mode of operation. 1: the data field transmitted on txd line is inverted (voltage polarity only) compared to the value written on us_thr or the co n- tent read in us_rhr is inverted compared to what is received on rxd line (or iso7816 io line). inverted mode of operation, useful for contactless card application. to be used with configuration bit msbf. ? var_sync: variable synchronization of command/data sync start frame delimiter 0: user defined configuration of command or data sync field depending on modsync value. 1: the sync field is updated when a character is written into us_thr. ? max_iteration: maximum number of automatic iteration 0 - 7: defines the maximum number of iterations in mode iso7816, protocol t = 0. ? filter: receive line filter 0: the usart does not filter the receive line. 1: the usart filters the receive line using a three-sample filter (1/16-bit clock) (2 over 3 majority). ? man: manchester encoder/decoder enable 0: manchester encoder/decoder are disabled. 1: manchester encoder/decoder are enabled. ? modsync: manchester synchronization mode 0:the manchester start bit is a 0 to 1 transition 1: the manchester start bit is a 1 to 0 transition. ? onebit: start frame delimiter selector 0: start frame delimiter is command or data sync. 1: start frame delimiter is one bit.
777 sam4cp [datasheet] 43051e?atpl?08/14 36.7.4 usart mode register (spi_mode) name: us_mr (spi_mode) address: 0x40024004 (0), 0x40028004 (1), 0x4002c004 (2), 0x40030004 (3), 0x40034004 (4) access: read/write this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 774 . this register can only be written if the wpen bit is cleared in ?usart write protection mode register? on page 798 . ? usart_mode: usart mode of operation ? usclks: clock selection ? chrl: character length ? cpha: spi clock phase applicable if usart operates in spi mode (usart_mode = 0xe or 0xf): 0: data is changed on the leading edge of spck and captured on the following edge of spck. 1: data is captured on the leading edge of spck and changed on the following edge of spck. cpha determines which edge of spck causes data to change and which edge causes data to be captured. cpha is used with cpol to produce the required clock/data relationship between master and slave devices. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? wrdbt ? clko ? cpol 15 14 13 12 11 10 9 8 ??????? cpha 76543210 chrl usclks usart_mode value name description 0xe spi_master spi master 0xf spi_slave spi slave value name description 0 mck peripheral clock is selected 1 div peripheral clock divided (div=8) is selected 3 sck serial clock slk is selected value name description 3 8_bit character length is 8 bits
778 sam4cp [datasheet] 43051e?atpl?08/14 ? cpol: spi clock polarity applicable if usart operates in spi mode (slave or master, usart_mode = 0xe or 0xf): 0: the inactive state value of spck is logic level zero. 1: the inactive state value of spck is logic level one. cpol is used to determine the inactive state value of the serial clock (spck). it is used with cpha to produce the required clock/data relationship between master and slave devices. ? clko: clock output select 0: the usart does not drive the sck pin. 1: the usart drives the sck pin if usclks does not select the external clock sck. ? wrdbt: wait read data before transfer 0: the character transmission starts as soon as a character is written into us_thr (assuming txrdy was set). 1: the character transmission starts when a character is written and only if rxrdy flag is cleared (receive holding register ha s been read).
779 sam4cp [datasheet] 43051e?atpl?08/14 36.7.5 usart interrupt enable register name: us_ier address: 0x40024008 (0), 0x40028008 (1), 0x4002c008 (2), 0x40030008 (3), 0x40034008 (4) access: write-only for spi specific configuration, see ?usart interrupt enable register (spi_mode)? on page 780 . the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? rxrdy: rxrdy interrupt enable ? txrdy: txrdy interrupt enable ? rxbrk: receiver break interrupt enable ? endrx: end of receive buffer interrupt enable (available in all usart modes of operation) ? endtx: end of transmit buffer interrupt enable (available in all usart modes of operation) ? ovre: overrun error interrupt enable ? frame: framing error interrupt enable ? pare: parity error interrupt enable ? timeout: time-out interrupt enable ? txempty: txempty interrupt enable ? iter: max number of repetitions reached interrupt enable ? txbufe: transmit buffer empty interrupt enable (available in all usart modes of operation) ? rxbuff: receive buffer full interrupt enable (available in all usart modes of operation) ? nack: non acknowledge interrupt enable ? ctsic: clear to send input change interrupt enable ? mane: manchester error interrupt enable 31 30 29 28 27 26 25 24 ??????? mane 23 22 21 20 19 18 17 16 ? ? ? ? ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
780 sam4cp [datasheet] 43051e?atpl?08/14 36.7.6 usart interrupt enable register (spi_mode) name: us_ier (spi_mode) address: 0x40024008 (0), 0x40028008 (1), 0x4002c008 (2), 0x40030008 (3), 0x40034008 (4) access: write-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 774 . the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? rxrdy: rxrdy interrupt enable ? txrdy: txrdy interrupt enable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? ovre: overrun error interrupt enable ? txempty: txempty interrupt enable ? unre: spi underrun error interrupt enable ? txbufe: transmit buffer empty interrupt enable ? rxbuff: receive buffer full interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
781 sam4cp [datasheet] 43051e?atpl?08/14 36.7.7 usart interrupt disable register name: us_idr address: 0x4002400c (0), 0x4002800c (1), 0x4002c00c (2), 0x4003000c (3), 0x4003400c (4) access: write-only for spi specific configuration, see ?usart interrupt disable register (spi_mode)? on page 782 . the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? rxrdy: rxrdy interrupt disable ? txrdy: txrdy interrupt disable ? rxbrk: receiver break interrupt disable ? endrx: end of receive buffer interrupt disable (available in all usart modes of operation) ? endtx: end of transmit buffer interrupt disable (available in all usart modes of operation) ? ovre: overrun error interrupt enable ? frame: framing error interrupt disable ? pare: parity error interrupt disable ? timeout: time-out interrupt disable ? txempty: txempty interrupt disable ? iter: max number of repetitions reached interrupt disable ? txbufe: transmit buffer empty interrupt disable (available in all usart modes of operation) ? rxbuff: receive buffer full interrupt disable (available in all usart modes of operation) ? nack: non acknowledge interrupt disable ? ctsic: clear to send input change interrupt disable ? mane: manchester error interrupt disable 31 30 29 28 27 26 25 24 ??????? mane 23 22 21 20 19 18 17 16 ? ? ? ? ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
782 sam4cp [datasheet] 43051e?atpl?08/14 36.7.8 usart interrupt disable register (spi_mode) name: us_idr (spi_mode) address: 0x4002400c (0), 0x4002800c (1), 0x4002c00c (2), 0x4003000c (3), 0x4003400c (4) access: write-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 774 . the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? rxrdy: rxrdy interrupt disable ? txrdy: txrdy interrupt disable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? ovre: overrun error interrupt disable ? txempty: txempty interrupt disable ? unre: spi underrun error interrupt disable ? txbufe: transmit buffer empty interrupt enable ? rxbuff: receive buffer full interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
783 sam4cp [datasheet] 43051e?atpl?08/14 36.7.9 usart interrupt mask register name: us_imr address: 0x40024010 (0), 0x40028010 (1), 0x4002c010 (2), 0x40030010 (3), 0x40034010 (4) access: read-only for spi specific configuration, see ?usart interrupt mask register (spi_mode)? on page 784 . the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? rxrdy: rxrdy interrupt mask ? txrdy: txrdy interrupt mask ? rxbrk: receiver break interrupt mask ? endrx: end of receive buffer interrupt mask (available in all usart modes of operation) ? endtx: end of transmit buffer interrupt mask (available in all usart modes of operation) ? ovre: overrun error interrupt mask ? frame: framing error interrupt mask ? pare: parity error interrupt mask ? timeout: time-out interrupt mask ? txempty: txempty interrupt mask ? iter: max number of repetitions reached interrupt mask ? txbufe: transmit buffer empty interrupt mask (available in all usart modes of operation) ? rxbuff: receive buffer full interrupt mask (available in all usart modes of operation) ? nack: non acknowledge interrupt mask ? ctsic: clear to send input change interrupt mask ? mane: manchester error interrupt mask 31 30 29 28 27 26 25 24 ??????? mane 23 22 21 20 19 18 17 16 ? ? ? ? ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
784 sam4cp [datasheet] 43051e?atpl?08/14 36.7.10 usart interrupt mask register (spi_mode) name: us_imr (spi_mode) address: 0x40024010 (0), 0x40028010 (1), 0x4002c010 (2), 0x40030010 (3), 0x40034010 (4) access: read-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 774 . the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? rxrdy: rxrdy interrupt mask ? txrdy: txrdy interrupt mask ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? ovre: overrun error interrupt mask ? txempty: txempty interrupt mask ? unre: spi underrun error interrupt mask ? txbufe: transmit buffer empty interrupt enable ? rxbuff: receive buffer full interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
785 sam4cp [datasheet] 43051e?atpl?08/14 36.7.11 usart channel status register name: us_csr address: 0x40024014 (0), 0x40028014 (1), 0x4002c014 (2), 0x40030014 (3), 0x40034014 (4) access: read-only for spi specific configuration, see ?usart channel status register (spi_mode)? on page 787 . ? rxrdy: receiver ready (automatically set / reset) 0: no complete character has been received since the last read of us_rhr or the receiver is disabled. if characters were being received when the receiver was disabled, rxrdy changes to 1 when the receiver is enabled. 1: at least one complete character has been received and us_rhr has not yet been read. ? txrdy: transmitter ready (automatically set / reset) 0: a character is in the us_thr waiting to be transferred to the transmit shift register, or an sttbrk command has been requested, or the transmitter is disabled. as soon as the transmitter is enabled, txrdy becomes 1. 1: there is no character in the us_thr. ? rxbrk: break received/end of break 0: no break received or end of break detected since the last rststa. 1: break received or end of break detected since the last rststa. ? endrx: end of rx buffer 0: the receive counter register has not reached 0 since the last write in us_rcr or us_rncr (1) . 1: the receive counter register has reached 0 since the last write in us_rcr or us_rncr (1) . ? endtx: end of tx buffer 0: the transmit counter register has not reached 0 since the last write in us_tcr or us_tncr (1) . 1: the transmit counter register has reached 0 since the last write in us_tcr or us_tncr (1) . ? ovre: overrun error 0: no overrun error has occurred since the last rststa. 1: at least one overrun error has occurred since the last rststa. ? frame: framing error 0: no stop bit has been detected low since the last rststa. 1: at least one stop bit has been detected low since the last rststa. 31 30 29 28 27 26 25 24 ??????? manerr 23 22 21 20 19 18 17 16 cts ? ? ? ctsic ? ? ? 15 14 13 12 11 10 9 8 ? ? nack rxbuff txbufe iter txempty timeout 76543210 pare frame ovre endtx endrx rxbrk txrdy rxrdy
786 sam4cp [datasheet] 43051e?atpl?08/14 ? pare: parity error 0: no parity error has been detected since the last rststa. 1: at least one parity error has been detected since the last rststa. ? timeout: receiver time-out 0: there has not been a time-out since the last start time-out command (sttto in us_cr) or the time-out register is 0. 1: there has been a time-out since the last start time-out command (sttto in us_cr). ? txempty: transmitter empty (automatically set / reset) 0: there are characters in either us_thr or the transmit shift register, or the transmitter is disabled. 1: there are no characters in us_thr, nor in the transmit shift register. ? iter: max number of repetitions reached 0: maximum number of repetitions has not been reached since the last rstit. 1: maximum number of repetitions has been reached since the last rstit. ? txbufe: tx buffer empty 0: us_tcr or us_tncr have a value other than 0 (1) . 1: both us_tcr and us_tncr have a value of 0 (1) . ? rxbuff: rx buffer full 0: us_rcr or us_rncr have a value other than 0 (1) . 1: both us_rcr and us_rncr have a value of 0 (1) . note: 1. us_rcr, us_rncr, us_tcr and us_tncr are pdc registers. ? nack: non acknowledge interrupt 0: non acknowledge has not been detected since the last rstnack. 1: at least one non acknowledge has been detected since the last rstnack. ? ctsic: clear to send input change flag (clear on read) 0: no input change has been detected on the cts pin since the last read of us_csr. 1: at least one input change has been detected on the cts pin since the last read of us_csr. ? cts: image of cts input 0: cts is set to 0. 1: cts is set to 1. ? manerr: manchester error 0: no manchester error has been detected since the last rststa. 1: at least one manchester error has been detected since the last rststa.
787 sam4cp [datasheet] 43051e?atpl?08/14 36.7.12 usart channel status register (spi_mode) name: us_csr (spi_mode) address: 0x40024014 (0), 0x40028014 (1), 0x4002c014 (2), 0x40030014 (3), 0x40034014 (4) access: read-only this configuration is relevant only if usart_mode = 0xe or 0xf in the ?usart mode register? on page 774 . ? rxrdy: receiver ready (automatically set / reset) 0: no complete character has been received since the last read of us_rhr or the receiver is disabled. if characters were being received when the receiver was disabled, rxrdy changes to 1 when the receiver is enabled. 1: at least one complete character has been received and us_rhr has not yet been read. ? txrdy: transmitter ready (automatically set / reset) 0: a character is in the us_thr waiting to be transferred to the transmit shift register or the transmitter is disabled. as soo n as the transmitter is enabled, txrdy becomes 1. 1: there is no character in the us_thr. ? ovre: overrun error 0: no overrun error has occurred since the last rststa. 1: at least one overrun error has occurred since the last rststa. ? txempty: transmitter empty (automatically set / reset) 0: there are characters in either us_thr or the transmit shift register, or the transmitter is disabled. 1: there are no characters in us_thr, nor in the transmit shift register. ? unre: underrun error 0: no spi underrun error has occurred since the last rststa. 1: at least one spi underrun error has occurred since the last rststa. ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? txbufe: transmit buffer empty interrupt enable ? rxbuff: receive buffer full interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? rxbuff txbufe unre txempty ? 76543210 ? ? ovre endtx endrx ? txrdy rxrdy
788 sam4cp [datasheet] 43051e?atpl?08/14 36.7.13 usart receive holding register name: us_rhr address: 0x40024018 (0), 0x40028018 (1), 0x4002c018 (2), 0x40030018 (3), 0x40034018 (4) access: read-only ? rxchr: received character last character received if rxrdy is set. ? rxsynh: received sync 0: last character received is a data. 1: last character received is a command. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rxsynh ? ? ???? rxchr 76543210 rxchr
789 sam4cp [datasheet] 43051e?atpl?08/14 36.7.14 usart transmit holding register name: us_thr address: 0x4002401c (0), 0x4002801c (1), 0x4002c01c (2), 0x4003001c (3), 0x4003401c (4) access: write-only ? txchr: character to be transmitted next character to be transmitted after the current character if txrdy is not set. ? txsynh: sync field to be transmitted 0: the next character sent is encoded as a data. start frame delimiter is data sync. 1: the next character sent is encoded as a command. start frame delimiter is command sync. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 txsynh ? ? ???? txchr 76543210 txchr
790 sam4cp [datasheet] 43051e?atpl?08/14 36.7.15 usart baud rate generator register name: us_brgr address: 0x40024020 (0), 0x40028020 (1), 0x4002c020 (2), 0x40030020 (3), 0x40034020 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? on page 798 . ? cd: clock divider ? fp: fractional part 0: fractional divider is disabled. 1 - 7: baud rate resolution, defined by fp x 1/8. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ????? fp 15 14 13 12 11 10 9 8 cd 76543210 cd cd usart_mode iso7816 usart_mode = iso7816 sync = 0 sync = 1 or usart_mode = spi (master or slave) over = 0 over = 1 0 baud rate clock disabled 1 to 65535 baud rate = selected clock/(16*cd) baud rate = selected clock/(8*cd) baud rate = selected clock/cd baud rate = selected clock/(fi_di_ratio*cd)
791 sam4cp [datasheet] 43051e?atpl?08/14 36.7.16 usart receiver time-out register name: us_rtor address: 0x40024024 (0), 0x40028024 (1), 0x4002c024 (2), 0x40030024 (3), 0x40034024 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? on page 798 . ? to: time-out value 0: the receiver time-out is disabled. 1 - 65535: the receiver time-out is enabled and the time-out delay is to x bit period. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 to 76543210 to
792 sam4cp [datasheet] 43051e?atpl?08/14 36.7.17 usart transmitter timeguard register name: us_ttgr address: 0x40024028 (0), 0x40028028 (1), 0x4002c028 (2), 0x40030028 (3), 0x40034028 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? on page 798 . ? tg: timeguard value 0: the transmitter timeguard is disabled. 1 - 255: the transmitter timeguard is enabled and the timeguard delay is tg x bit period. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 tg
793 sam4cp [datasheet] 43051e?atpl?08/14 36.7.18 usart fi di ratio register name: us_fidi address: 0x40024040 (0), 0x40028040 (1), 0x4002c040 (2), 0x40030040 (3), 0x40034040 (4) access: read/write reset: 0x174 this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? on page 798 . ? fi_di_ratio: fi over di ratio value 0: if iso7816 mode is selected, the baud rate generator generates no signal. 1 - 2: do not use. 3 - 2047: if iso7816 mode is selected, the baud rate is the clock provided on sck divided by fi_di_ratio. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? ? fi_di_ratio 76543210 fi_di_ratio
794 sam4cp [datasheet] 43051e?atpl?08/14 36.7.19 usart number of errors register name: us_ner address: 0x40024044 (0), 0x40028044 (1), 0x4002c044 (2), 0x40030044 (3), 0x40034044 (4) access: read-only this register is relevant only if usart_mode = 0x4 or 0x6 in the ?usart mode register? on page 774 . ? nb_errors: number of errors total number of errors that occurred during an iso7816 transfer. this register automatically clears when read. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 nb_errors
795 sam4cp [datasheet] 43051e?atpl?08/14 36.7.20 usart irda filter register name: us_if address: 0x4002404c (0), 0x4002804c (1), 0x4002c04c (2), 0x4003004c (3), 0x4003404c (4) access: read/write this register is relevant only if usart_mode = 0x8 in the ?usart mode register? on page 774 . this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? on page 798 . ? irda_filter: irda filter the irda_filter value must be defined to meet the following criteria: t peripheral clock * (irda_filter + 3) < 1.41 s 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 irda_filter
796 sam4cp [datasheet] 43051e?atpl?08/14 36.7.21 usart manchester configuration register name: us_man address: 0x40024050 (0), 0x40028050 (1), 0x4002c050 (2), 0x40030050 (3), 0x40034050 (4) access: read/write this register can only be written if the wpen bit is cleared in the ?usart write protection mode register? on page 798 . ? tx_pl: transmitter preamble length 0: the transmitter preamble pattern generation is disabled. 1 - 15: the preamble length is tx_pl x bit period. ? tx_pp: transmitter preamble pattern the following values assume that tx_mpol field is not set: ? tx_mpol: transmitter manchester polarity 0: logic zero is coded as a zero-to-one transition, logic one is coded as a one-to-zero transition. 1: logic zero is coded as a one-to-zero transition, logic one is coded as a zero-to-one transition. ? rx_pl: receiver preamble length 0: the receiver preamble pattern detection is disabled. 1 - 15: the detected preamble length is rx_pl x bit period. ? rx_pp: receiver preamble pattern detected the following values assume that rx_mpol field is not set: 31 30 29 28 27 26 25 24 rxidlev drift one rx_mpol ? ? rx_pp 23 22 21 20 19 18 17 16 ? ? ? ? rx_pl 15 14 13 12 11 10 9 8 ? ? ? tx_mpol ? ? tx_pp 76543210 ???? tx_pl value name description 0 all_one the preamble is composed of ?1?s 1 all_zero the preamble is composed of ?0?s 2 zero_one the preamble is composed of ?01?s 3 one_zero the preamble is composed of ?10?s value name description 00 all_one the preamble is composed of ?1?s 01 all_zero the preamble is composed of ?0?s 10 zero_one the preamble is composed of ?01?s 11 one_zero the preamble is composed of ?10?s
797 sam4cp [datasheet] 43051e?atpl?08/14 ? rx_mpol: receiver manchester polarity 0: logic zero is coded as a zero-to-one transition, logic one is coded as a one-to-zero transition. 1: logic zero is coded as a one-to-zero transition, logic one is coded as a zero-to-one transition. ? one: must be set to 1 bit 29 must always be set to 1 when programming the us_man register. ? drift: drift compensation 0: the usart cannot recover from an important clock drift. 1: the usart can recover from clock drift. the 16x clock mode must be enabled. ? rxidlev: receiver idle value 0: receiver line idle value is 0. 1: receiver line idle value is 1.
798 sam4cp [datasheet] 43051e?atpl?08/14 36.7.22 usart write protection mode register name: us_wpmr address: 0x400240e4 (0), 0x400280e4 (1), 0x4002c0e4 (2), 0x400300e4 (3), 0x400340e4 (4) access: read/write reset: see table 36-14 ? wpen: write protection enable 0: disables the write protection if wpkey corresponds to 0x555341 (?usa? in ascii). 1: enables the write protection if wpkey corresponds to 0x555341 (?usa? in ascii). see section 36.6.9 ?register write protection? for the list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x555341 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
799 sam4cp [datasheet] 43051e?atpl?08/14 36.7.23 usart write protection status register name: us_wpsr address: 0x400240e8 (0), 0x400280e8 (1), 0x4002c0e8 (2), 0x400300e8 (3), 0x400340e8 (4) access: read-only reset: see table 36-14 ? wpvs: write protection violation status 0: no write protection violation has occurred since the last read of the us_wpsr. 1: a write protection violation has occurred since the last read of the us_wpsr. if this violation is an unauthorized attempt t o write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
800 sam4cp [datasheet] 43051e?atpl?08/14 37. timer counter (tc) 37.1 description the timer counter (tc) includes three identical 16-bit timer counter channels. each channel can be independently programmed to perform a wide range of functions including frequency measurement, event counting, interval measurement, pulse generation, delay timing and pulse width modulation. each channel has three external clock inputs, five internal clock inputs and two multi-purpose input/output signals which can be configured by the user. each channel drives an internal interrupt signal which can be programmed to generate processor interrupts. the timer counter (tc) embeds a quadrature decoder logic connected in front of the timers and driven by tioa0, tiob0 and tiob1 inputs. when enabled, the quadrature decoder performs the input lines filtering, decoding of quadrature signals and connects to the timers/counters in order to read the position and speed of the motor through the user interface. the timer counter block has two global registers which act upon all tc channels: ? block control register (tc_bcr) allows the channels to be started simultaneously with the same instruction. ? block mode register (tc_bmr) defines the external clock inputs for each channel, allowing them to be chained. table 37-1 gives the assignment of the device timer counter clock inputs common to timer counter 0 to 2. note: 1. when slow clock is selected for peripheral clock (css = 0 in pmc master clock register), timer_clock5 input is equivalent to peripheral clock. 37.2 embedded characteristics ? provides three 16-bit timer counter channels ? wide range of functions including: ? frequency measurement ? event counting ? interval measurement ? pulse generation ? delay timing ? pulse width modulation ? up/down capabilities ? quadrature decoder logic ? 2-bit gray up/down count for stepper motor ? each channel is user-configurable and contains: ? three external clock inputs ? five internal clock inputs ? two multi-purpose input/output signals acting as trigger event ? internal interrupt signal table 37-1. timer counter clock assignment name definition timer_clock1 mck/2 timer_clock2 mck/8 timer_clock3 mck/32 timer_clock4 mck/128 timer_clock5 (1) slck
801 sam4cp [datasheet] 43051e?atpl?08/14 ? two global registers that act on all tc channels ? register write protection 37.3 block diagram figure 37-1. timer counter block diagram table 37-2. signal name description block/channel signal name description channel signal xc0, xc1, xc2 external clock inputs tioa capture mode: timer counter input waveform mode: timer counter output tiob capture mode: timer counter input waveform mode: timer counter input/output int interrupt signal output (internal signal) sync synchronization input signal (from configuration register) timer/counter channel 0 timer/counter channel 1 timer/counter channel 2 sync parallel i/o controller tc1xc1s tc0xc0s tc2xc2s int0 int1 int2 tioa0 tioa1 tioa2 tiob0 tiob1 tiob2 xc0 xc1 xc2 xc0 xc1 xc2 xc0 xc1 xc2 tclk0 tclk1 tclk2 tclk0 tclk1 tclk2 tclk0 tclk1 tclk2 tioa1 tioa2 tioa0 tioa2 tioa0 tioa1 interrupt controller tclk0 tclk1 tclk2 tioa0 tiob0 tioa1 tiob1 tioa2 tiob2 timer counter tioa tiob tioa tiob tioa tiob sync sync timer_clock2 timer_clock3 timer_clock4 timer_clock5 timer_clock1
802 sam4cp [datasheet] 43051e?atpl?08/14 37.4 pin name list 37.5 product dependencies 37.5.1 i/o lines the pins used for interfacing the compl iant external devices may be multiple xed with pio lines. the programmer must first program the pio controllers to assign the tc pins to their peripheral functions. 37.5.2 power management the tc is clocked through the power management controller (pmc), thus the programmer must first configure the pmc to enable the timer counter clock. 37.5.3 interrupt the tc has an interrupt line connected to the interrupt controller (ic). handling the tc interrupt requires programming the ic before configuring the tc. table 37-3. tc pin list pin name description type tclk0 - tclk2 external clock input input tioa0 - tioa2 i/o line a i/o tiob0 - tiob2 i/o line b i/o table 37-4. i/o lines instance signal i/o line peripheral tc0 tclk0 pb4 b tc0 tclk1 pb9 a tc0 tclk2 pb12 a tc0 tioa0 pa13 b tc0 tioa1 pb7 a tc0 tioa2 pb10 a tc0 tiob0 pa14 b tc0 tiob1 pb8 a tc0 tiob2 pb11 a tc1 tclk3 pb26 a tc1 tclk4 pa17 b tc1 tclk5 pa19 b tc1 tioa3 pb24 a tc1 tioa4 pa15 b tc1 tioa5 pa18 b tc1 tiob3 pb25 a tc1 tiob4 pa16 b tc1 tiob5 pa20 b
803 sam4cp [datasheet] 43051e?atpl?08/14 37.6 functional description 37.6.1 tc description the three channels of the timer counter are independent and identical in operation except when quadrature decoder is enabled. the registers for channel programming are listed in table 37-5 on page 822 . 37.6.2 16-bit counter each channel is organized around a 16-bit counter. the value of the counter is incremented at each positive edge of the selected clock. when the counter has reached the value 2 16 - 1 and passes to zero, an overflow occurs and the covfs bit in the tc status register (tc_sr) is set. the current value of the counter is accessible in real time by reading the tc counter value register (tc_cv). the counter can be reset by a trigger. in this case, the counter value passes to zero on the next valid edge of the selected clock. 37.6.3 clock selection at block level, input clock signals of each channel can either be connected to the external inputs tclk0, tclk1 or tclk2, or be connected to the internal i/o signals tioa0, tioa1 or tioa2 for chaining by programming the tc block mode register (tc_bmr). see figure 37-2 ?clock chaining selection? . each channel can independently select an internal or external clock source for its counter: ? internal clock signals: timer_clock1, timer_clock2, timer_clock3, timer_clock4, timer_clock5 ? external clock signals: xc0, xc1 or xc2 this selection is made by the tcclks bits in the tc channel mode register (tc_cmr). the selected clock can be inverted with the clki bit in the tc_cmr. this allows counting on the opposite edges of the clock. the burst function allows the clock to be validated when an external signal is high. the burst parameter in the tc_cmr defines this signal (none, xc0, xc1, xc2). see figure 37-3 ?clock selection? . note: in all cases, if an external clock is used, the duration of each of its levels must be longer than the peripheral clock period. the external clock frequency must be at least 2.5 times lower than the peripheral clock.
804 sam4cp [datasheet] 43051e?atpl?08/14 figure 37-2. clock chaining selection figure 37-3. clock selection timer/counter channel 0 sync tc0xc0s tioa0 tiob0 xc0 xc1 = tclk1 xc2 = tclk2 tclk0 tioa1 tioa2 timer/counter channel 1 sync tc1xc1s tioa1 tiob1 xc0 = tclk0 xc1 xc2 = tclk2 tclk1 tioa0 tioa2 timer/counter channel 2 sync tc2xc2s tioa2 tiob2 xc0 = tclk0 xc1 = tclk1 xc2 tclk2 tioa0 tioa1 timer_clock1 timer_clock2 timer_clock3 timer_clock4 timer_clock5 xc0 xc1 xc2 tcclks clki synchronous edge detection burst peripheral clock 1 se l e c t e d clock
805 sam4cp [datasheet] 43051e?atpl?08/14 37.6.4 clock control the clock of each counter can be controlled in two different ways: it can be enabled/disabled and started/stopped. see figure 37-4 . ? the clock can be enabled or disabled by the user with the clken and the clkdis commands in the tc channel control register (tc_ccr). in capture mode it can be disabled by an rb load event if ldbdis is set to 1 in the tc_cmr. in waveform mode, it can be disabled by an rc compare event if cpcdis is set to 1 in tc_cmr. when disabled, the start or the stop actions have no effect: only a clken command in the tc_ccr can re- enable the clock. when the clock is enabled, the clksta bit is set in the tc_sr. ? the clock can also be started or stopped: a trigger (software, synchro, external or compare) always starts the clock. the clock can be stopped by an rb load event in capture mode (ldbstop = 1 in tc_cmr) or a rc compare event in waveform mode (cpcstop = 1 in tc_cmr). the start and the stop commands have effect only if the clock is enabled. figure 37-4. clock control 37.6.5 tc operating modes each channel can independently operate in two different modes: ? capture mode provides measurement on signals. ? waveform mode provides wave generation. the tc operating mode is programmed with the wave bit in the tc channel mode register. in capture mode, tioa and tiob are configured as inputs. in waveform mode, tioa is always configured to be an output and tiob is an output if it is not selected to be the external trigger. 37.6.6 trigger a trigger resets the counter and starts the counter clock. three types of triggers are common to both modes, and a fourth external trigger is available to each mode. regardless of the trigger used, it will be taken into account at the following active edge of the selected clock. this means that the counter value can be read differently from zero just after a trigger, especially when a low frequency signal is selected as the clock. qs r s r q clksta clken clkdis stop event disable event counter clock selected clock trigger
806 sam4cp [datasheet] 43051e?atpl?08/14 the following triggers are common to both modes: ? software trigger: each channel has a software trigger, available by setting swtrg in tc_ccr. ? sync: each channel has a synchronization signal sync. when asserted, this signal has the same effect as a software trigger. the sync signals of all channels are asserted simultaneously by writing tc_bcr (block control) with sync set. ? compare rc trigger: rc is implemented in each channel and can provide a trigger when the counter value matches the rc value if cpctrg is set in the tc_cmr. the channel can also be configured to have an external trigger. in capture mode, the external trigger signal can be selected between tioa and tiob. in waveform mode, an external event can be programmed on one of the following signals: tiob, xc0, xc1 or xc2. this external event can then be programmed to perform a trigger by setting bit enetrg in the tc_cmr. if an external trigger is used, the duration of the pulses must be longer than the peripheral clock period in order to be detected. 37.6.7 capture operating mode this mode is entered by clearing the wave bit in the tc_cmr. capture mode allows the tc channel to perform measurements such as pulse timing, frequency, period, duty cycle and phase on tioa and tiob signals which are considered as inputs. figure 37-5 shows the configuration of the tc channel when programmed in capture mode. 37.6.8 capture registers a and b registers a and b (ra and rb) are used as capture registers. this means that they can be loaded with the counter value when a programmable event occurs on the signal tioa. the ldra field in the tc_cmr defines the tioa selected edge for the loading of register a, and the ldrb field defines the tioa selected edge for the loading of register b. ra is loaded only if it has not been loaded since the last trigger or if rb has been loaded since the last loading of ra. rb is loaded only if ra has been loaded since the last trigger or the last loading of rb. loading ra or rb before the read of the last value loaded sets the overrun error flag (lovrs bit) in the tc_sr. in this case, the old value is overwritten.
807 sam4cp [datasheet] 43051e?atpl?08/14 figure 37-5. capture mode timer_clock1 timer_clock2 timer_clock3 timer_clock4 timer_clock5 xc0 xc1 xc2 tcclks clki qs r s r q clksta clken clkdis burst tiob register c capture register a capture register b compare rc = counter abetrg swtrg etrgedg cpctrg tc1_imr trig ldrbs ldras etrgs tc1_sr lovrs covfs sync 1 mtiob tioa mtioa ldra ldbstop if ra is not loaded or rb is loaded if ra is loaded ldbdis cpcs int edge detector edge detector ldrb edge detector clk ovf reset timer/counter channel peripheral clock synchronous edge detection
808 sam4cp [datasheet] 43051e?atpl?08/14 37.6.9 trigger conditions in addition to the sync signal, the software trigger and the rc compare trigger, an external trigger can be defined. the abetrg bit in the tc_cmr selects tioa or tiob input signal as an external trigger. the external trigger edge selection parameter (etrgedg field in tc_cmr) defines the edge (rising, falling or both) detected to generate an external trigger. if etrgedg = 0 (none), the external trigger is disabled. 37.6.10 waveform operating mode waveform operating mode is entered by setting the wave parameter in tc_cmr (channel mode register). in waveform operating mode the tc channel generates 1 or 2 pwm signals with the same frequency and independently programmable duty cycles, or generates different types of one-shot or repetitive pulses. in this mode, tioa is configured as an output and tiob is defined as an output if it is not used as an external event (eevt parameter in tc_cmr). figure 37-6 shows the configuration of the tc channel when programmed in waveform operating mode. 37.6.11 waveform selection depending on the wavsel parameter in tc_cmr (channel mode register), the behavior of tc_cv varies. with any selection, tc_ra, tc_rb and tc_rc can all be used as compare registers. ra compare is used to control the tioa output, rb compare is used to control the tiob output (if correctly configured) and rc compare is used to control tioa and/or tiob outputs.
809 sam4cp [datasheet] 43051e?atpl?08/14 figure 37-6. waveform mode tcclks clki qs r s r q clksta clken clkdis cpcdis burst tiob register a register b register c compare ra = compare rb = compare rc = cpcstop counter eevt eevtedg sync swtrg enetrg wavsel tc1_imr trig acpc acpa aeevt aswtrg bcpc bcpb beevt bswtrg tioa mtioa tiob mtiob cpas covfs etrgs tc1_sr cpcs cpbs clk ovf reset output controller output controller int 1 edge detector timer/counter channel timer_clock1 timer_clock2 timer_clock3 timer_clock4 timer_clock5 xc0 xc1 xc2 wavsel peripheral clock synchronous edge detection
810 sam4cp [datasheet] 43051e?atpl?08/14 37.6.11.1 wavsel = 00 when wavsel = 00, the value of tc_cv is incremented from 0 to 2 16 - 1. once 2 16 - 1has been reached, the value of tc_cv is reset. incrementation of tc_cv starts again and the cycle continues. see figure 37-7 . an external event trigger or a software trigger can reset the value of tc_cv. it is important to note that the trigger may occur at any time. see figure 37-8 . rc compare cannot be programmed to generate a trigger in this configuration. at the same time, rc compare can stop the counter clock (cpcstop = 1 in tc_cmr) and/or disable the counter clock (cpcdis = 1 in tc_cmr). figure 37-7. wavsel = 00 without trigger figure 37-8. wavsel = 00 with trigger time counter value r c r b r a tiob tioa counter cleared by compare match with 0xffff 0xffff waveform examples time counter value r c r b r a tiob tioa counter cleared by compare match with 0xffff 0xffff waveform examples counter cleared by trigger
811 sam4cp [datasheet] 43051e?atpl?08/14 37.6.11.2 wavsel = 10 when wavsel = 10, the value of tc_cv is incremented from 0 to the value of rc, then automatically reset on a rc compare. once the value of tc_cv has been reset, it is then incremented and so on. see figure 37-9 . it is important to note that tc_cv can be reset at any time by an external event or a software trigger if both are programmed correctly. see figure 37-10 . in addition, rc compare can stop the counter clock (cpcstop = 1 in tc_cmr) and/or disable the counter clock (cpcdis = 1 in tc_cmr). figure 37-9. wavsel = 10 without trigger figure 37-10. wavsel = 10 with trigger time counter value r c r b r a tiob tioa counter cleared by compare match with rc waveform examples 2 n -1 (n = counter size) time counter value r c r b r a tiob tioa counter cleared by compare match with rc waveform examples counter cleared by trigger 2 n -1 (n = counter size)
812 sam4cp [datasheet] 43051e?atpl?08/14 37.6.11.3 wavsel = 01 when wavsel = 01, the value of tc_cv is incremented from 0 to 2 16 - 1. once 2 16 - 1 is reached, the value of tc_cv is decremented to 0, then re-incremented to 2 16 - 1 and so on. see figure 37-11 . a trigger such as an external event or a software trigger can modify tc_cv at any time. if a trigger occurs while tc_cv is incrementing, tc_cv then decrements. if a trigger is received while tc_cv is decrementing, tc_cv then increments. see figure 37-12 . rc compare cannot be programmed to generate a trigger in this configuration. at the same time, rc compare can stop the counter clock (cpcstop = 1) and/or disable the counter clock (cpcdis = 1). figure 37-11. wavsel = 01 without trigger figure 37-12. wavsel = 01 with trigger time counter value r c r b r a tiob tioa counter decremented by compare match with 0xffff 0xffff waveform examples time counter value tiob tioa counter decremented by compare match with 0xffff 0xffff waveform examples counter decremented by trigger counter incremented by trigger r c r b r a
813 sam4cp [datasheet] 43051e?atpl?08/14 37.6.11.4 wavsel = 11 when wavsel = 11, the value of tc_cv is incremented from 0 to rc. once rc is reached, the value of tc_cv is decremented to 0, then re-incremented to rc and so on. see figure 37-13 . a trigger such as an external event or a software trigger can modify tc_cv at any time. if a trigger occurs while tc_cv is incrementing, tc_cv then decrements. if a trigger is received while tc_cv is decrementing, tc_cv then increments. see figure 37-14 . rc compare can stop the counter clock (cpcstop = 1) and/or disable the counter clock (cpcdis = 1). figure 37-13. wavsel = 11 without trigger figure 37-14. wavsel = 11 with trigger time counter value r c r b r a tiob tioa counter decremented by compare match with rc waveform examples 2 n -1 (n = counter size) time counter value tiob tioa counter decremented by compare match with rc waveform examples counter decremented by trigger counter incremented by trigger r c r b r a 2 n -1 (n = counter size)
814 sam4cp [datasheet] 43051e?atpl?08/14 37.6.12 external event/trigger conditions an external event can be programmed to be detected on one of the clock sources (xc0, xc1, xc2) or tiob. the external event selected can then be used as a trigger. the eevt parameter in tc_cmr selects the external trigger. the eevtedg parameter defines the trigger edge for each of the possible external triggers (rising, falling or both). if eevtedg is cleared (none), no external event is defined. if tiob is defined as an external event signal (eevt = 0), tiob is no longer used as an output and the compare register b is not used to generate waveforms and subsequently no irqs. in this case the tc channel can only generate a waveform on tioa. when an external event is defined, it can be used as a trigger by setting bit enetrg in the tc_cmr. as in capture mode, the sync signal and the software tri gger are also available as triggers. rc compare can also be used as a trigger depending on the parameter wavsel. 37.6.13 output controller the output controller defines the output level changes on tioa and tiob following an event. tiob control is used only if tiob is defined as output (not as an external event). the following events control tioa and tiob: software trigger, external event and rc compare. ra compare controls tioa and rb compare controls tiob. each of these events can be programmed to set, clear or toggle the output as defined in the corresponding parameter in tc_cmr. 37.6.14 quadrature decoder logic 37.6.14.1 description the quadrature decoder logic is driven by tioa0, tiob0, tiob1 input pins and drives the timer/counter of channel 0 and channel 1. channel 2 can be used as a time base in case of speed measurement requirements (refer to figure 37-15 ?predefined connection of the quadrature decoder with timer counters? ). when writing a 0 to bit qden of the tc_bmr, the quadrature decoder logic is totally transparent. tioa0 and tiob0 are to be driven by the two dedicated quadrature signals from a rotary sensor mounted on the shaft of the off-chip motor. a third signal from the rotary sensor can be processed thro ugh pin tiob1 and is typically dedicated to be driven by an index signal if it is provided by the sensor. this signal is not required to decode the quadrature signals pha, phb. field tcclks of tc_cmrx must be configured to select xc0 input (i.e., 0x101). field tc0xc0s has no effect as soon as quadrature decoder is enabled. either speed or position/revolution can be measured. position channel 0 accumulates the edges of pha, phb input signals giving a high accuracy on motor position whereas channel 1 accumulates the index pulses of the sensor, therefore the number of rotations. concatenation of both values provides a high level of precision on motion system position. in speed mode, position cannot be measured but revolution can be measured. inputs from the rotary sensor can be filtered prior to down-stream processing. accommod ation of input polarity, phase definition and other factors are configurable. interruptions can be generated on different events. a compare function (using tc_rc) is available on channel 0 (speed/position) or channel 1 (rotation) and can generate an interrupt by means of the cpcs flag in the tc_srx.
815 sam4cp [datasheet] 43051e?atpl?08/14 figure 37-15. predefined connection of the quadrature decoder with timer counters timer/counter channel 0 1 xc0 tioa tiob timer/counter channel 1 1 xc0 tiob qden timer/counter channel 2 1 tiob0 xc0 1 1 speeden 1 xc0 quadrature decoder (filter + edge detect + qd) pha phb idx tioa0 tiob0 tiob1 tiob1 tioa0 index speed/position rotation speed time base reset pulse direction phedges qden
816 sam4cp [datasheet] 43051e?atpl?08/14 37.6.14.2 input pre-processing input pre-processing consists of capabilities to take into account rotary sensor factors such as polarities and phase definition followed by configurable digital filtering. each input can be negated and swapping pha, phb is also configurable. the maxfilt field in the tc_bmr is used to configure a minimum duration for which the pulse is stated as valid. when the filter is active, pulses with a duration lower than maxfilt+1 * t peripheral clock ns are not passed to down-stream logic. figure 37-16. input stage input filtering can efficiently remove spurious pulses that might be generated by the presence of particulate contamination on the optical or magnetic disk of the rotary sensor. spurious pulses can also occur in environments with high levels of electro-magnetic interference. or, simply if vibration occurs even when rotation is fully stopped and the shaft of the motor is in such a position that the beginning of one of the reflective or magnetic bars on the rotary sensor disk is aligned with the light or magnetic (hall) receiver cell of the rotary sensor. any vibration can make the pha, phb signals toggle for a short duration. 1 1 1 maxfilt pha phb idx t ioa0 t iob0 t iob1 inva 1 invb 1 invidx swap 1 idxphb filter filter filter 1 maxfilt > 0 direction and edge detection idx phedge dir input pre-processing
817 sam4cp [datasheet] 43051e?atpl?08/14 figure 37-17. filtering examples pha,b filter out peripheral clock maxfilt=2 particulate contamination pha phb motor shaft stopped in such a position that rotary sensor cell is aligned with an edge of the disk rotation pha phb phb edge area due to system vibration resulting pha, phb electrical waveforms pha optical/magnetic disk strips stop phb mechanical shock on system vibration stop pha, phb electrical waveforms after filtering pha phb
818 sam4cp [datasheet] 43051e?atpl?08/14 37.6.14.3 direction status and change detection after filtering, the quadrature signals are analyzed to extract the rotation direction and edges of the two quadrature signals detected in order to be counted by timer/counter logic downstream. the direction status can be directly read at anytime in the tc_qisr. the polarity of the direction flag status depends on the configuration written in tc_bmr. inva, invb, invidx, swap modify the polarity of dir flag. any change in rotation direction is reported in the tc_qisr and can generate an interrupt. the direction change condition is reported as soon as two consecutive edges on a phase signal have sampled the same value on the other phase signal and there is an edge on the other signal. the two consecutive edges of one phase signal sampling the same value on other phase signal is not sufficient to declare a direction change, for the reason that particulate contamination may mask one or more reflective bars on the optical or magnetic disk of the sensor. (refer to figure 37-18 ?rotation change detection? for waveforms.) figure 37-18. rotation change detection the direction change detection is disabled when qdtrans is set in the tc_bmr. in this case the dir flag report must not be used. a quadrature error is also reported by the quadrature decoder logic via the qerr flag in the tc_qisr. this error is reported if the time difference between two edges on pha, phb is lower than a predefined value. this predefined value is configurable and corresponds to (maxfilt+1) * t peripheral clock ns. after being filtered there is no reason to have two edges closer than (maxfilt+1) * t peripheral clock ns under normal mode of operation. pha phb direction change under normal conditions dir dirchg change condition report time no direction change due to particulate contamination masking a reflective bar pha phb dir dirchg spurious change condition (if detected in a simple way) same phase missing pulse
819 sam4cp [datasheet] 43051e?atpl?08/14 figure 37-19. quadrature error detection maxfilt must be tuned according to several factors such as the peripheral clock frequency, type of rotary sensor and rotation speed to be achieved. 37.6.14.4 position and rotation measurement when the posen bit is set in the tc_b mr, the motor axis position is proce ssed on channel 0 (by means of the pha, phb edge detections) and the number of motor revolutions are recorded on channel 1 if the idx signal is provided on the tiob1 input. the position measurement can be read in the tc_cv0 register and the rotation measurement can be read in the tc_cv1 register. channel 0 and 1 must be configured in capture mode (wave = 0 in tc_cmr0). in parallel, the number of edges are accumulated on timer/counter channel 0 and can be read on the tc_cv0 register. therefore, the accurate position can be read on both tc_cv registers and concatenated to form a 32-bit word. the timer/counter channel 0 is cleared for each increment of idx count value. depending on the quadrature signals, the direction is decoded and allows to count up or down in timer/counter channels 0 and 1. the direction status is reported on tc_qisr. 37.6.14.5 speed measurement when speeden is set in the tc_bmr, the speed measure is enabled on channel 0. a time base must be defined on channel 2 by writing the tc_rc2 period register. channel 2 must be configured in waveform mode (wave bit set) in tc_cmr2. the wavsel field must be defined with 0x10 to clear the counter by comparison and matching with tc_rc value. field acpc must be defined at 0x11 to toggle tioa output. this time base is automatically fed back to tioa of channel 0 when qden and speeden are set. peripheral clock maxfilt = 2 pha phb abnormally formatted optical disk strips (theoretical view) pha phb strip edge inaccurary due to disk etching/printing process resulting pha, phb electrical waveforms pha phb even with an abnormally formatted disk, there is no occurence of pha, phb switching at the same time. qerr duration < maxfilt
820 sam4cp [datasheet] 43051e?atpl?08/14 channel 0 must be configured in capture mode (wave = 0 in tc_cmr0). the abetrg bit of tc_cmr0 must be configured at 1 to select tioa as a trigger for this channel. edgtrg can be set to 0x01, to clear the counter on a rising edge of the tioa signal and field ldra must be set accordingly to 0x01, to load tc_ra0 at the same time as the counter is cleared (ldrb must be set to 0x01). as a consequence, at the end of each time base period the differentiation required for the speed calculation is performed. the process must be started by configuring bits clken and swtrg in the tc_ccr. the speed can be read on field ra in tc_ra0. channel 1 can still be used to count the number of revolutions of the motor. 37.6.14.6 missing pulse detection and auto-correction the qdec is equipped with a circuitry which detects and corrects some errors that may result from contamination on optical disks or other materials producing the quadrature phase signals. the detection and autocorrection only works if the count mode is configured for both phases (edgpha = 1 in tc_bmr) and is enabled (autoc = 1 in tc_bmr). if a pulse is missing on a phase signal, it is automatically detected and the pulse count reported in the cv field of the tc_cv0/1 is automatically corrected. there is no detection if both phase signals are affected at the same location on the device providing the quadrature signals because the detection requires a valid phase signal to detect the contamination on the other phase signal. figure 37-20. detection and auto-correction of missing pulses if a quadrature device is undamaged, the number of pulses counted for a predefined period of time must be the same with or without detection and auto-correction feature. therefore, if the measurement results differ, a contamination exists on the device producing the quadrature signals. this does not substitute the measurements of the number of pulses between two index pulses (if available) but provides a complementary method to detect damaged quadrature devices. when the device providing quadrature signals is severely damaged, potentially leading to a number of consecutive missing pulses greater than 1, the downstream processing may be affected. it is possible to define the maximum admissible number of consecutive missing pulses before issuing a missing pulse error flag (mpe in tc_qisr). the threshold triggering a mpe flag report can be configured in field maxcmp of the tc_bmr. if the field maxcmp is cleared, mpe never rises. the flag maxcmp can trigger an interrupt while the qdec is operating, thus providing a real time report of a potential problem on the quadrature device. pha phb missing pulse due to a conta m ination (dust, scratch, ...) not a change of direction detection 123 45 6 7 101213141516 corrections
821 sam4cp [datasheet] 43051e?atpl?08/14 37.6.15 2-bit gray up/down counter for stepper motor each channel can be independently configured to generate a 2-bit gray count waveform on corresponding tioa,tiob outputs by means of the gcen bit in tc_smmrx. up or down count can be defined by writing bit down in tc_smmrx. it is mandatory to configure the channel in wave mode in the tc_cmr. the period of the counters can be programmed in tc_rcx. figure 37-21. 2-bit gray up/down counter 37.6.16 register write protection to prevent any single software error fr om corrupting tc behavior, certain regi sters in the address space can be write- protected by setting the wpen bit in the ?tc write protection mode register? (tc_wpmr). the following registers can be write-protected: ? ?tc block mode register? ? ?tc channel mode register: capture mode? ? ?tc channel mode register: waveform mode? ? ?tc stepper motor mode register? ? ?tc register a? ? ?tc register b? ? ?tc register c? tioax tiobx downx tc_rcx wavex = gcenx =1
822 sam4cp [datasheet] 43051e?atpl?08/14 37.7 timer counter (tc) user interface notes: 1. channel index ranges from 0 to 2. 2. read-only if wave = 0. table 37-5. register mapping offset (1) register name access reset 0x00 + channel * 0x40 + 0x00 channel control register tc_ccr write-only ? 0x00 + channel * 0x40 + 0x04 channel mode register tc_cmr read/write 0 0x00 + channel * 0x40 + 0x08 stepper motor mode register tc_smmr read/write 0 0x00 + channel * 0x40 + 0x0c reserved ? ? ? 0x00 + channel * 0x40 + 0x10 counter value tc_cv read-only 0 0x00 + channel * 0x40 + 0x14 register a tc_ra read/write (2) 0 0x00 + channel * 0x40 + 0x18 register b tc_rb read/write (2) 0 0x00 + channel * 0x40 + 0x1c register c tc_rc read/write 0 0x00 + channel * 0x40 + 0x20 status register tc_sr read-only 0 0x00 + channel * 0x40 + 0x24 interrupt enable register tc_ier write-only ? 0x00 + channel * 0x40 + 0x28 interrupt disable register tc_idr write-only ? 0x00 + channel * 0x40 + 0x2c interrupt mask register tc_imr read-only 0 0xc0 block control register tc_bcr write-only ? 0xc4 block mode register tc_bmr read/write 0 0xc8 qdec interrupt enable register tc_qier write-only ? 0xcc qdec interrupt disable register tc_qidr write-only ? 0xd0 qdec interrupt mask register tc_qimr read-only 0 0xd4 qdec interrupt status register tc_qisr read-only 0 0xd8 reserved ? ? ? 0xe4 write protection mode register tc_wpmr read/write 0 0xe8 - 0xfc reserved ? ? ?
823 sam4cp [datasheet] 43051e?atpl?08/14 37.7.1 tc channel control register name: tc_ccrx [x=0..2] address: 0x40010000 (0)[0], 0x40010040 (0)[1], 0x40010080 (0)[2], 0x40014000 (1)[0], 0x40014040 (1)[1], 0x40014080 (1)[2] access: write-only ? clken: counter clock enable command 0 = no effect. 1 = enables the clock if clkdis is not 1. ? clkdis: counter clock disable command 0 = no effect. 1 = disables the clock. ? swtrg: software trigger command 0 = no effect. 1 = a software trigger is performed: the counter is reset and the clock is started. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? swtrg clkdis clken
824 sam4cp [datasheet] 43051e?atpl?08/14 37.7.2 tc channel mode register: capture mode name: tc_cmrx [x=0..2] (wave = 0) address: 0x40010004 (0)[0], 0x40010044 (0)[1], 0x40010084 (0)[2], 0x40014004 (1)[0], 0x40014044 (1)[1], 0x40014084 (1)[2] access: read/write this register can only be written if the wpen bit is cleared in the ?tc write protection mode register? on page 847 . ? tcclks: clock selection ? clki: clock invert 0 = counter is incremented on rising edge of the clock. 1 = counter is incremented on falling edge of the clock. ? burst: burst signal selection ? ldbstop: counter clock stopped with rb loading 0 = counter clock is not stopped when rb loading occurs. 1 = counter clock is stopped when rb loading occurs. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ldrb ldra 15 14 13 12 11 10 9 8 wave cpctrg ? ? ? abetrg etrgedg 76543210 ldbdis ldbstop burst clki tcclks value name description 0 timer_clock1 clock selected: internal timer_clock1 clock signal (from pmc). 1 timer_clock2 clock selected: internal timer_clock2 clock signal (from pmc). 2 timer_clock3 clock selected: internal timer_clock3 clock signal (from pmc). 3 timer_clock4 clock selected: internal timer_clock4 clock signal (from pmc). 4 timer_clock5 clock selected: internal timer_clock5 clock signal (from pmc). 5 xc0 clock selected: xc0. 6 xc1 clock selected: xc1. 7 xc2 clock selected: xc2. value name description 0 none the clock is not gated by an external signal. 1 xc0 xc0 is anded with the selected clock. 2 xc1 xc1 is anded with the selected clock. 3 xc2 xc2 is anded with the selected clock.
825 sam4cp [datasheet] 43051e?atpl?08/14 ? ldbdis: counter clock disable with rb loading 0 = counter clock is not disabled when rb loading occurs. 1 = counter clock is disabled when rb loading occurs. ? etrgedg: external trigger edge selection ? abetrg: tioa or tiob external trigger selection 0 = tiob is used as an external trigger. 1 = tioa is used as an external trigger. ? cpctrg: rc compare trigger enable 0 = rc compare has no effect on the counter and its clock. 1 = rc compare resets the counter and starts the counter clock. ? wave: waveform mode 0 = capture mode is enabled. 1 = capture mode is disabled (waveform mode is enabled). ? ldra: ra loading edge selection ? ldrb: rb loading edge selection value name description 0 none the clock is not gated by an external signal. 1 rising rising edge. 2 falling falling edge. 3 edge each edge. value name description 0 none none. 1 rising rising edge of tioa. 2 falling falling edge of tioa. 3 edge each edge of tioa. value name description 0 none none. 1 rising rising edge of tioa. 2 falling falling edge of tioa. 3 edge each edge of tioa.
826 sam4cp [datasheet] 43051e?atpl?08/14 37.7.3 tc channel mode register: waveform mode name: tc_cmrx [x=0..2] (wave = 1) access: read/write this register can only be written if the wpen bit is cleared in the ?tc write protection mode register? on page 847 . ? tcclks: clock selection ? clki: clock invert 0 = counter is incremented on rising edge of the clock. 1 = counter is incremented on falling edge of the clock. ? burst: burst signal selection ? cpcstop: counter clock stopped with rc compare 0 = counter clock is not stopped when counter reaches rc. 1 = counter clock is stopped when counter reaches rc. 31 30 29 28 27 26 25 24 bswtrg beevt bcpc bcpb 23 22 21 20 19 18 17 16 aswtrg aeevt acpc acpa 15 14 13 12 11 10 9 8 wave wavsel enetrg eevt eevtedg 76543210 cpcdis cpcstop burst clki tcclks value name description 0 timer_clock1 clock selected: internal timer_clock1 clock signal (from pmc). 1 timer_clock2 clock selected: internal timer_clock2 clock signal (from pmc). 2 timer_clock3 clock selected: internal timer_clock3 clock signal (from pmc). 3 timer_clock4 clock selected: internal timer_clock4 clock signal (from pmc). 4 timer_clock5 clock selected: internal timer_clock5 clock signal (from pmc). 5 xc0 clock selected: xc0. 6 xc1 clock selected: xc1. 7 xc2 clock selected: xc2. value name description 0 none the clock is not gated by an external signal. 1 xc0 xc0 is anded with the selected clock. 2 xc1 xc1 is anded with the selected clock. 3 xc2 xc2 is anded with the selected clock.
827 sam4cp [datasheet] 43051e?atpl?08/14 ? cpcdis: counter clock disable with rc compare 0 = counter clock is not disabled when counter reaches rc. 1 = counter clock is disabled when counter reaches rc. ? eevtedg: external event edge selection ? eevt: external event selection signal selected as external event. notes: 1. if tiob is chosen as the external event signal, it is configured as an input and no longer generates waveforms and subsequently no irqs. ? enetrg: external event trigger enable 0 = the external event has no effect on the counter and its clock. 1 = the external event resets the counter and starts the counter clock. note: whatever the value programmed in enetrg, the selected external event only controls the tioa output and tiob if not used as input (trigger event input or other input used). ? wavsel: waveform selection ? wave: waveform mode 0 = waveform mode is disabled (capture mode is enabled). 1 = waveform mode is enabled. value name description 0 none none 1 rising rising edge 2 falling falling edge 3 edge each edge value name description tiob direction 0 tiob tiob (1) input 1 xc0 xc0 output 2 xc1 xc1 output 3 xc2 xc2 output value name description 0 up up mode without automatic trigger on rc compare. 1 updown updown mode without automatic trigger on rc compare. 2 up_rc up mode with automatic trigger on rc compare. 3 updown_rc updown mode with automatic trigger on rc compare.
828 sam4cp [datasheet] 43051e?atpl?08/14 ? acpa: ra compare effect on tioa ? acpc: rc compare effect on tioa ? aeevt: external event effect on tioa ? aswtrg: software trigger effect on tioa ? bcpb: rb compare effect on tiob value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle
829 sam4cp [datasheet] 43051e?atpl?08/14 ? bcpc: rc compare effect on tiob ? beevt: external event effect on tiob ? bswtrg: software trigger effect on tiob value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle value name description 0 none none 1 set set 2 clear clear 3 toggle toggle
830 sam4cp [datasheet] 43051e?atpl?08/14 37.7.4 tc stepper motor mode register name: tc_smmrx [x=0..2] address: 0x40010008 (0)[0], 0x40010048 (0)[1], 0x40010088 (0)[2], 0x40014008 (1)[0], 0x40014048 (1)[1], 0x40014088 (1)[2] access: read/write this register can only be written if the wpen bit is cleared in the ?tc write protection mode register? on page 847 . ? gcen: gray count enable 0 = tioax [x=0..2] and tiobx [x=0..2] are driven by internal counter of channel x. 1 = tioax [x=0..2] and tiobx [x=0..2] are driven by a 2-bit gray counter. ? down: down count 0 = up counter. 1 = down counter. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ? down gcen
831 sam4cp [datasheet] 43051e?atpl?08/14 37.7.5 tc counter value register name: tc_cvx [x=0..2] address: 0x40010010 (0)[0], 0x40010050 (0)[1], 0x40010090 (0)[2], 0x40014010 (1)[0], 0x40014050 (1)[1], 0x40014090 (1)[2] access: read-only ? cv: counter value cv contains the counter value in real time. 31 30 29 28 27 26 25 24 cv 23 22 21 20 19 18 17 16 cv 15 14 13 12 11 10 9 8 cv 76543210 cv
832 sam4cp [datasheet] 43051e?atpl?08/14 37.7.6 tc register a name: tc_rax [x=0..2] address: 0x40010014 (0)[0], 0x40010054 (0)[1], 0x40010094 (0)[2], 0x40014014 (1)[0], 0x40014054 (1)[1], 0x40014094 (1)[2] access: read-only if wave = 0, read/write if wave = 1 this register can only be written if the wpen bit is cleared in the ?tc write protection mode register? on page 847 . ? ra: register a ra contains the register a value in real time. 31 30 29 28 27 26 25 24 ra 23 22 21 20 19 18 17 16 ra 15 14 13 12 11 10 9 8 ra 76543210 ra
833 sam4cp [datasheet] 43051e?atpl?08/14 37.7.7 tc register b name: tc_rbx [x=0..2] address: 0x40010018 (0)[0], 0x40010058 (0)[1], 0x40010098 (0)[2], 0x40014018 (1)[0], 0x40014058 (1)[1], 0x40014098 (1)[2] access: read-only if wave = 0, read/write if wave = 1 this register can only be written if the wpen bit is cleared in the ?tc write protection mode register? on page 847 . ? rb: register b rb contains the register b value in real time. 31 30 29 28 27 26 25 24 rb 23 22 21 20 19 18 17 16 rb 15 14 13 12 11 10 9 8 rb 76543210 rb
834 sam4cp [datasheet] 43051e?atpl?08/14 37.7.8 tc register c name: tc_rcx [x=0..2] address: 0x4001001c (0)[0], 0x4001005c (0)[1], 0x4001009c (0)[2], 0x4001401c (1)[0], 0x4001405c (1)[1], 0x4001409c (1)[2] access: read/write this register can only be written if the wpen bit is cleared in the ?tc write protection mode register? on page 847 . ? rc: register c rc contains the register c value in real time. 31 30 29 28 27 26 25 24 rc 23 22 21 20 19 18 17 16 rc 15 14 13 12 11 10 9 8 rc 76543210 rc
835 sam4cp [datasheet] 43051e?atpl?08/14 37.7.9 tc status register name: tc_srx [x=0..2] address: 0x40010020 (0)[0], 0x40010060 (0)[1], 0x400100a0 (0)[2], 0x40014020 (1)[0], 0x40014060 (1)[1], 0x400140a0 (1)[2] access: read-only ? covfs: counter overflow status 0 = no counter overflow has occurred since the last read of the status register. 1 = a counter overflow has occurred since the last read of the status register. ? lovrs: load overrun status 0 = load overrun has not occurred since the last read of the status register or wave = 1. 1 = ra or rb have been loaded at least twice without any read of the corresponding register since the last read of the status register, if wave = 0. ? cpas: ra compare status 0 = ra compare has not occurred since the last read of the status register or wave = 0. 1 = ra compare has occurred since the last read of the status register, if wave = 1. ? cpbs: rb compare status 0 = rb compare has not occurred since the last read of the status register or wave = 0. 1 = rb compare has occurred since the last read of the status register, if wave = 1. ? cpcs: rc compare status 0 = rc compare has not occurred since the last read of the status register. 1 = rc compare has occurred since the last read of the status register. ? ldras: ra loading status 0 = ra load has not occurred since the last read of the status register or wave = 1. 1 = ra load has occurred since the last read of the status register, if wave = 0. ? ldrbs: rb loading status 0 = rb load has not occurred since the last read of the status register or wave = 1. 1 = rb load has occurred since the last read of the status register, if wave = 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ? mtiob mtioa clksta 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
836 sam4cp [datasheet] 43051e?atpl?08/14 ? etrgs: external trigger status 0 = external trigger has not occurred since the last read of the status register. 1 = external trigger has occurred since the last read of the status register. ? clksta: clock enabling status 0 = clock is disabled. 1 = clock is enabled. ? mtioa: tioa mirror 0 = tioa is low. if wave = 0, this means that tioa pin is low. if wave = 1, this means that tioa is driven low. 1 = tioa is high. if wave = 0, this means that tioa pin is high. if wave = 1, this means that tioa is driven high. ? mtiob: tiob mirror 0 = tiob is low. if wave = 0, this means that tiob pin is low. if wave = 1, this means that tiob is driven low. 1 = tiob is high. if wave = 0, this means that tiob pin is high. if wave = 1, this means that tiob is driven high.
837 sam4cp [datasheet] 43051e?atpl?08/14 37.7.10 tc interrupt enable register name: tc_ierx [x=0..2] address: 0x40010024 (0)[0], 0x40010064 (0)[1], 0x400100a4 (0)[2], 0x40014024 (1)[0], 0x40014064 (1)[1], 0x400140a4 (1)[2] access: write-only ? covfs: counter overflow 0 = no effect. 1 = enables the counter overflow interrupt. ? lovrs: load overrun 0 = no effect. 1 = enables the load overrun interrupt. ? cpas: ra compare 0 = no effect. 1 = enables the ra compare interrupt. ? cpbs: rb compare 0 = no effect. 1 = enables the rb compare interrupt. ? cpcs: rc compare 0 = no effect. 1 = enables the rc compare interrupt. ? ldras: ra loading 0 = no effect. 1 = enables the ra load interrupt. ? ldrbs: rb loading 0 = no effect. 1 = enables the rb load interrupt. ? etrgs: external trigger 0 = no effect. 1 = enables the external trigger interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
838 sam4cp [datasheet] 43051e?atpl?08/14 37.7.11 tc interrupt disable register name: tc_idrx [x=0..2] address: 0x40010028 (0)[0], 0x40010068 (0)[1], 0x400100a8 (0)[2], 0x40014028 (1)[0], 0x40014068 (1)[1], 0x400140a8 (1)[2] access: write-only ? covfs: counter overflow 0 = no effect. 1 = disables the counter overflow interrupt. ? lovrs: load overrun 0 = no effect. 1 = disables the load overrun interrupt (if wave = 0). ? cpas: ra compare 0 = no effect. 1 = disables the ra compare interrupt (if wave = 1). ? cpbs: rb compare 0 = no effect. 1 = disables the rb compare interrupt (if wave = 1). ? cpcs: rc compare 0 = no effect. 1 = disables the rc compare interrupt. ? ldras: ra loading 0 = no effect. 1 = disables the ra load interrupt (if wave = 0). ? ldrbs: rb loading 0 = no effect. 1 = disables the rb load interrupt (if wave = 0). ? etrgs: external trigger 0 = no effect. 1 = disables the external trigger interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
839 sam4cp [datasheet] 43051e?atpl?08/14 37.7.12 tc interrupt mask register name: tc_imrx [x=0..2] address: 0x4001002c (0)[0], 0x4001006c (0)[1], 0x400100ac (0)[2], 0x4001402c (1)[0], 0x4001406c (1)[1], 0x400140ac (1)[2] access: read-only ? covfs: counter overflow 0 = the counter overflow interrupt is disabled. 1 = the counter overflow interrupt is enabled. ? lovrs: load overrun 0 = the load overrun interrupt is disabled. 1 = the load overrun interrupt is enabled. ? cpas: ra compare 0 = the ra compare interrupt is disabled. 1 = the ra compare interrupt is enabled. ? cpbs: rb compare 0 = the rb compare interrupt is disabled. 1 = the rb compare interrupt is enabled. ? cpcs: rc compare 0 = the rc compare interrupt is disabled. 1 = the rc compare interrupt is enabled. ? ldras: ra loading 0 = the load ra interrupt is disabled. 1 = the load ra interrupt is enabled. ? ldrbs: rb loading 0 = the load rb interrupt is disabled. 1 = the load rb interrupt is enabled. ? etrgs: external trigger 0 = the external trigger interrupt is disabled. 1 = the external trigger interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 etrgs ldrbs ldras cpcs cpbs cpas lovrs covfs
840 sam4cp [datasheet] 43051e?atpl?08/14 37.7.13 tc block control register name: tc_bcr address: 0x400100c0 (0), 0x400140c0 (1) access: write-only ? sync: synchro command 0 = no effect. 1 = asserts the sync signal which generates a software trigger simultaneously for each of the channels. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ??????? sync
841 sam4cp [datasheet] 43051e?atpl?08/14 37.7.14 tc block mode register name: tc_bmr address: 0x400100c4 (0), 0x400140c4 (1) access: read/write this register can only be written if the wpen bit is cleared in the ?tc write protection mode register? on page 847 . ? tc0xc0s: external clock signal 0 selection ? tc1xc1s: external clock signal 1 selection ? tc2xc2s: external clock signal 2 selection ? qden: quadrature decoder enabled 0 = disabled. 1 = enables the quadrature decoder logic (filter, edge detection and quadrature decoding). quadrature decoding (direction change) can be disabled using qdtrans bit. one of the posen or speeden bits must be also enabled. 31 30 29 28 27 26 25 24 ? ? maxcmp maxfilt 23 22 21 20 19 18 17 16 maxfilt ? autoc idxphb swap 15 14 13 12 11 10 9 8 invidx invb inva edgpha qdtrans speeden posen qden 76543210 ? ? tc2xc2s tc1xc1s tc0xc0s value name description 0 tclk0 signal connected to xc0: tclk0 1 ? reserved 2 tioa1 signal connected to xc0: tioa1 3 tioa2 signal connected to xc0: tioa2 value name description 0 tclk1 signal connected to xc1: tclk1 1 ? reserved 2 tioa0 signal connected to xc1: tioa0 3 tioa2 signal connected to xc1: tioa2 value name description 0 tclk2 signal connected to xc2: tclk2 1 ? reserved 2 tioa0 signal connected to xc2: tioa0 3 tioa1 signal connected to xc2: tioa1
842 sam4cp [datasheet] 43051e?atpl?08/14 ? posen: position enabled 0 = disable position. 1 = enables the position measure on channel 0 and 1. ? speeden: speed enabled 0 = disabled. 1 = enables the speed measure on channel 0, the time base being provided by channel 2. ? qdtrans: quadrature decoding transparent 0 = full quadrature decoding logic is active (direction change detected). 1 = quadrature decoding logic is inactive (direction change inactive) but input filtering and edge detection are performed. ? edgpha: edge on pha count mode 0 = edges are detected on pha only. 1 = edges are detected on both pha and phb. ? inva: inverted pha 0 = pha (tioa0) is directly driving quadrature decoder logic. 1 = pha is inverted before driving quadrature decoder logic. ? invb: inverted phb 0 = phb (tiob0) is directly driving quadrature decoder logic. 1 = phb is inverted before driving quadrature decoder logic. ? swap: swap pha and phb 0 = no swap between pha and phb. 1 = swap pha and phb internally, prior to driving quadrature decoder logic. ? invidx: inverted index 0 = idx (tioa1) is directly driving quadrature logic. 1 = idx is inverted before driving quadrature logic. ? idxphb: index pin is phb pin 0 = idx pin of the rotary sensor must drive tioa1. 1 = idx pin of the rotary sensor must drive tiob0. ? autoc: auto-correction of missing pulses 0 (disabled) = the detection and auto-correction function is disabled. 1 (enabled) = the detection and auto-correction function is enabled. ? maxfilt: maximum filter 1?63 = defines the filtering capabilities. pulses with a period shorter than maxfilt+1 peripheral clock cycles are discarded. ? maxcmp: maximum consecutive missing pulses 0 = the flag mpe in tc_qisr never rises. 1?15 = defines the number of consecutive missing pulses before a flag report.
843 sam4cp [datasheet] 43051e?atpl?08/14 37.7.15 tc qdec interrupt enable register name: tc_qier address: 0x400100c8 (0), 0x400140c8 (1) access: write-only ? idx: index 0 = no effect. 1 = enables the interrupt when a rising edge occurs on idx input. ? dirchg: direction change 0 = no effect. 1 = enables the interrupt when a change on rotation direction is detected. ? qerr: quadrature error 0 = no effect. 1 = enables the interrupt when a quadrature error occurs on pha, phb. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? qerr dirchg idx
844 sam4cp [datasheet] 43051e?atpl?08/14 37.7.16 tc qdec interrupt disable register name: tc_qidr address: 0x400100cc (0), 0x400140cc (1) access: write-only ? idx: index 0 = no effect. 1 = disables the interrupt when a rising edge occurs on idx input. ? dirchg: direction change 0 = no effect. 1 = disables the interrupt when a change on rotation direction is detected. ? qerr: quadrature error 0 = no effect. 1 = disables the interrupt when a quadrature error occurs on pha, phb. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? qerr dirchg idx
845 sam4cp [datasheet] 43051e?atpl?08/14 37.7.17 tc qdec interrupt mask register name: tc_qimr address: 0x400100d0 (0), 0x400140d0 (1) access: read-only ? idx: index 0 = the interrupt on idx input is disabled. 1 = the interrupt on idx input is enabled. ? dirchg: direction change 0 = the interrupt on rotation direction change is disabled. 1 = the interrupt on rotation direction change is enabled. ? qerr: quadrature error 0 = the interrupt on quadrature error is disabled. 1 = the interrupt on quadrature error is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? qerr dirchg idx
846 sam4cp [datasheet] 43051e?atpl?08/14 37.7.18 tc qdec interrupt status register name: tc_qisr address: 0x400100d4 (0), 0x400140d4 (1) access: read-only ? idx: index 0 = no index input change since the last read of tc_qisr. 1 = the idx input has changed since the last read of tc_qisr. ? dirchg: direction change 0 = no change on rotation direction since the last read of tc_qisr. 1 = the rotation direction changed since the last read of tc_qisr. ? qerr: quadrature error 0 = no quadrature error since the last read of tc_qisr. 1 = a quadrature error occurred since the last read of tc_qisr. ? dir: direction returns an image of the actual rotation direction. ? mpe: consecutive missing pulse error 0 = the number of consecutive missing puls es has not reached the maximum value spec ified in maxmp since the last read of tc_qisr. 1 = an occurrence of maxcmp consecutive missing pulses has been detected since the last read of tc_qisr. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????dir 76543210 ? ? ? ? mpe qerr dirchg idx
847 sam4cp [datasheet] 43051e?atpl?08/14 37.7.19 tc write protection mode register name: tc_wpmr address: 0x400100e4 (0), 0x400140e4 (1) access: read/write ? wpen: write protection enable 0 = disables the write protection if wpkey corresponds to 0x54494d (?tim? in ascii). 1 = enables the write protection if wpkey corresponds to 0x54494d (?tim? in ascii). see section 37.6.16 ?register write protection?, for list of registers that can be write-protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x54494d passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
848 sam4cp [datasheet] 43051e?atpl?08/14 38. pulse width modulation controller (pwm) 38.1 description the pwm macrocell controls several channels independently. each channel controls one square output waveform. characteristics of the output waveform such as period, duty-cycle and polarity are configurable through the user interface. each channel selects and uses one of the clocks provided by the clock generator. the clock generator provides several clocks resulting from the division of the pwm macrocell master clock. all pwm macrocell accesses are made through apb mapped registers. channels can be synchronized, to generate non overlapped waveforms. all channels integrate a double buffering system in order to prevent an unexpected output waveform while modifying the period or the duty-cycle. 38.2 embedded characteristics ? 4 channels ? one 16-bit counter per channel ? common clock generator providing thirteen different clocks ? a modulo n counter providing eleven clocks ? two independent linear dividers working on modulo n counter outputs ? independent channels ? independent enable disable command for each channel ? independent clock selection for each channel ? independent period and duty cycle for each channel ? double buffering of period or duty cycle for each channel ? programmable selection of the output waveform polarity for each channel ? programmable center or left aligned output waveform for each channel block diagram
849 sam4cp [datasheet] 43051e?atpl?08/14 38.3 block diagram figure 38-1. pulse width modulation controller block diagram 38.4 i/o lines description each channel outputs one waveform on one external i/o line. pwm controller apb pwmx pwmx pwmx channel update duty cycle counter pwm0 channel pio interrupt controller pmc mck clock generator apb interface interrupt generator clock selector period update duty cycle counter clock selector period pwm0 pwm0 comparator comparator table 38-1. i/o line description name description type pwmx pwm waveform output for channel x output
850 sam4cp [datasheet] 43051e?atpl?08/14 38.5 product dependencies 38.5.1 i/o lines the pins used for interfacing the pwm may be multiplex ed with pio lines. the programmer must first program the pio controller to assign the desired pwm pins to their peripheral function. if i/o lines of the pwm are not used by the application, they can be used for other purposes by the pio controller. all of the pwm outputs may or may not be enabled. if an application requires only four channels, then only four pio lines will be assigned to pwm outputs. 38.5.2 power management the pwm is not continuously clocked. the programmer must first enable the pwm clock in the power management controller (pmc) before using the pwm. however, if the application does not require pwm operations, the pwm clock can be stopped when not needed and be restarted later. in this case, the pwm will resume its operations where it left off. all the pwm registers except pwm_cdty and pwm_cprd can be read without the pwm peripheral clock enabled. all the registers can be written without the peripheral clock enabled. 38.5.3 interrupt sources the pwm interrupt line is connected on one of the internal sources of the interrupt controller. using the pwm interrupt requires the interrupt controller to be programmed first. note that it is not recommended to use the pwm interrupt line in edge sensitive mode. 38.6 functional description the pwm macrocell is primarily composed of a clock generator module and 4 channels. ? clocked by the system clock, mck, the clock generator module provides 13 clocks. ? each channel can independently choose one of the clock generator outputs. ? each channel generates an output waveform with attributes that can be defined independently for each channel through the user interface registers. table 38-2. i/o lines instance signal i/o line peripheral pwm pwm0 pc0 b pwm pwm0 pc6 a pwm pwm1 pc1 b pwm pwm1 pc7 a pwm pwm2 pc2 b pwm pwm2 pc8 a pwm pwm3 pc3 b pwm pwm3 pc9 a table 38-3. peripheral ids instance id pwm 41
851 sam4cp [datasheet] 43051e?atpl?08/14 38.6.1 pwm clock generator figure 38-2. functional view of the clock generator block diagram caution: before using the pwm macrocell, the programmer must first enable the pwm clock in the power management controller (pmc). the pwm macrocell master clock, mck, is divided in the clock generator module to provide different clocks available for all channels. each channel can independently select one of the divided clocks. the clock generator is divided in three blocks: ? a modulo n counter which provides 11 clocks: f mck , f mck /2, f mck /4, f mck /8, f mck /16, f mck /32, f mck /64, f mck /128, f mck /256, f mck /512, f mck /1024. ? two linear dividers (1, 1/2, 1/3,... 1/255) that provide two separate clocks: clka and clkb. each linear divider can independently divide one of the clocks of the modulo n counter. the selection of the clock to be divided is made according to the prea (preb) field of the pwm mode register (pwm_mr). the resulting clock clka (clkb) is the clock selected divided by diva (divb) field value in the pwm mode register (pwm_mr). after a reset of the pwm controller, diva (divb) and prea (preb) in the pwm mode register are set to 0. this implies that after reset clka (clkb) are turned off. at reset, all clocks provided by the modulo n counter are turned off except clock ?clk?. this situation is also true when the pwm master clock is turned off through the power management controller. modulo n counter mck mck/2 mck/4 mck/16 mck/32 mck/64 mck/8 divider a clka diva pwm_mr mck mck/128 mck/256 mck/512 mck/1024 prea divider b clkb divb pwm_mr preb
852 sam4cp [datasheet] 43051e?atpl?08/14 38.6.2 pwm channel 38.6.2.1 block diagram figure 38-3. functional view of the channel block diagram each of the 4 channels is composed of three blocks: ? a clock selector which selects one of the clocks provided by the clock generator described in section 38.6.1 ?pwm clock generator? on page 851 . ? an internal counter clocked by the output of the clock selector. this internal counter is incremented or decremented according to the channel configuration and comparators events. the size of the internal counter is 16 bits. ? a comparator used to generate events according to the internal counter value. it also computes the pwmx output waveform according to the configuration. 38.6.2.2 waveform properties the different properties of output waveforms are: ? the internal clock selection . the internal channel counter is clocked by one of the clocks provided by the clock generator described in the previous section. this channel parameter is defined in the cpre field of the pwm_cmrx register. this field is reset at 0. ? the waveform period . this channel parameter is defined in the cprd field of the pwm_cprdx register. if the waveform is left aligned, then the output waveform period depends on the counter source clock and can be calculated: by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024), the resulting period formula will be: by using a master clock divided by one of both diva or divb divider, the formula becomes, respectively: or if the waveform is center aligned then the output waveform period depends on the counter source clock and can be calculated: by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). the resulting period formula will be: by using a master clock divided by one of both diva or divb divider, the formula becomes, respectively: or comparator pwmx output waveform internal counter clock selector inputs from clock generator inputs from apb bus channel x * cprd ?? mck ------------------------------ x * cprd * diva ?? mck ------------------------------------------------ x * cprd * divb ?? mck ------------------------------------------------ 2* x * cprd ?? mck ------------------------------------ - 2* x * cprd * diva ?? mck ------------------------------------------------------ - 2* x * cprd * divb ?? mck ------------------------------------------------------ -
853 sam4cp [datasheet] 43051e?atpl?08/14 ? the waveform duty cycle . this channel parameter is defined in the cdty field of the pwm_cdtyx register. if the waveform is left aligned then: if the waveform is center aligned, then: ? the waveform polarity. at the beginning of the period, the signal can be at high or low level. this property is defined in the cpol field of the pwm_cmrx register. by default the signal starts by a low level. ? the waveform alignment . the output waveform can be left or center aligned. center aligned waveforms can be used to generate non overlapped waveforms. this property is defined in the calg field of the pwm_cmrx register. the default mode is left aligned. figure 38-4. non overlapped center aligned waveforms note: 1. see figure 38-5 on page 854 for a detailed description of center aligned waveforms. when center aligned, the internal channel counter increases up to cprd and.decreases down to 0. this ends the period. when left aligned, the internal channel counter increases up to cprd and is reset. this ends the period. thus, for the same cprd value, the period for a center aligned channel is twice the period for a left aligned channel. waveforms are fixed at 0 when: ? cdty = cprd and cpol = 0 ? cdty = 0 and cpol = 1 waveforms are fixed at 1 (once the channel is enabled) when: ? cdty = 0 and cpol = 0 ? cdty = cprd and cpol = 1 the waveform polarity must be set before enabling the channel. this immediately affects the channel output level. changes on channel polarity are not taken into account while the channel is enabled. duty cycle period 1 fchannel_x_clock cdty ? ? ? ?? period ---------------------------------------------------------------------------------------------------------- - = duty cycle period 2 ? ?? 1 fchannel_x_clock cdty ? ? ? ??? period 2 ? ?? ------------------------------------------------------------------------------------------------------------------------- - = pwm0 pwm1 period no overlap
854 sam4cp [datasheet] 43051e?atpl?08/14 figure 38-5. waveform properties pwm_mckx chidx(pwm_sr) center aligned cprd(pwm_cprdx) cdty(pwm_cdtyx) pwm_ccntx output waveform pwmx cpol(pwm_cmrx) = 0 output waveform pwmx cpol(pwm_cmrx) = 1 chidx(pwm_isr) left aligned cprd(pwm_cprdx) cdty(pwm_cdtyx) pwm_ccntx output waveform pwmx cpol(pwm_cmrx) = 0 output waveform pwmx cpol(pwm_cmrx) = 1 chidx(pwm_isr) calg(pwm_cmrx) = 0 calg(pwm_cmrx) = 1 period period chidx(pwm_ena) chidx(pwm_dis)
855 sam4cp [datasheet] 43051e?atpl?08/14 38.6.3 pwm controller operations 38.6.3.1 initialization before enabling the output channel, this channel must have been configured by the software application: ? configuration of the clock generator if diva and divb are required. ? selection of the clock for each channel (cpre field in the pwm_cmrx register). ? configuration of the waveform alignment for each channel (calg field in the pwm_cmrx register). ? configuration of the period for each channel (cprd in the pwm_cprdx register). writing in pwm_cprdx register is possible while the channel is disabled. after validation of the channel, the user must use pwm_cupdx register to update pwm_cprdx as explained below. ? configuration of the duty cycle for each channel (cdty in the pwm_cdtyx register). writing in pwm_cdtyx register is possible while the channel is disabled. after validation of the channel, the user must use pwm_cupdx register to update pwm_cdtyx as explained below. ? configuration of the output waveform polarity for each channel (cpol in the pwm_cmrx register). ? enable interrupts (writing chidx in the pwm_ier register). ? enable the pwm channel (writing chidx in the pwm_ena register). it is possible to synchronize different channels by enabling them at the same time by means of writing simultaneously several chidx bits in the pwm_ena register. ? in such a situation, all channels may have the same clock selector configuration and the same period specified. 38.6.3.2 source clock selection criteria the large number of source clocks can make selection difficult. the relationship between the value in the period register (pwm_cprdx) and the duty cycle register (pwm_cdtyx) can help the user in choosing. the event number written in the period register gives the pwm accuracy. the duty cycle quantum cannot be lower than 1/pwm_cprdx value. the higher the value of pwm_cprdx, the greater the pwm accuracy. for example, if the user sets 15 (in decimal) in pwm_cprdx, the user is able to set a value between 1 up to 14 in pwm_cdtyx register. the resulting duty cycle quantum cannot be lower than 1/15 of the pwm period. 38.6.3.3 changing the duty cycle or the period it is possible to modulate the output waveform duty cycle or period. to prevent unexpected output waveform, the user must use the update register (pwm_cupdx) to change waveform parameters while the channel is still enabled. the user can write a new period value or duty cycle value in the update register (pwm_cupdx). this register holds the new value until the end of the current cycle and updates the value for the next cycle. depending on the cpd field in the pwm_cmrx register, pwm_cupdx either updates pwm_cprdx or pwm_cdtyx. note that even if the update register is used, the period must not be smaller than the duty cycle.
856 sam4cp [datasheet] 43051e?atpl?08/14 figure 38-6. synchronized period or duty cycle update to prevent overwriting the pwm_cupdx by software, the user can use status events in order to synchronize his software. two methods are possible. in both, the user must enable the dedicated interrupt in pwm_ier at pwm controller level. the first method (polling method) consists of reading the relevant status bit in pwm_isr register according to the enabled channel(s). see figure 38-7 . the second method uses an interrupt service routine associated with the pwm channel. note: reading the pwm_isr register automatically clears chidx flags. figure 38-7. polling method note: polarity and alignment can be modified only when the channel is disabled. 38.6.3.4 interrupts depending on the interrupt mask in the pwm_imr register, an interrupt is generated at the end of the corresponding channel period. the interrupt remains active until a read operation in the pwm_isr register occurs. a channel interrupt is enabled by setting the corresponding bit in the pwm_ier register. a channel interrupt is disabled by setting the corresponding bit in the pwm_idr register. pwm_cupdx value pwm_cprdx pwm_cdtyx end of cycle pwm_cmrx. cpd user's writing 1 0 writing in pwm_cupdx the last write has been taken into account chidx = 1 writing in cpd field update of the period or duty cycle pwm_isr read acknowledgement and clear previous register state yes
857 sam4cp [datasheet] 43051e?atpl?08/14 38.7 pulse width modulation controller (pwm) user interface notes: 1. some registers are indexed with ?ch_num? index ranging from 0 to 3. table 38-4. register mapping (1) offset register name access reset 0x00 pwm mode register pwm_mr read/write 0 0x04 pwm enable register pwm_ena write-only - 0x08 pwm disable register pwm_dis write-only - 0x0c pwm status register pwm_sr read-only 0 0x10 pwm interrupt enable register pwm_ier write-only - 0x14 pwm interrupt disable register pwm_idr write-only - 0x18 pwm interrupt mask register pwm_imr read-only 0 0x1c pwm interrupt status register pwm_isr read-only 0 0x20 - 0xfc reserved ? ? ? 0x100 - 0x1fc reserved ? ? ? 0x200 + ch_num * 0x20 + 0x00 pwm channel mode register pwm_cmr read/write 0x0 0x200 + ch_num * 0x20 + 0x04 pwm channel duty cycle register pwm_cdty read/write 0x0 0x200 + ch_num * 0x20 + 0x08 pwm channel period register pwm_cprd read/write 0x0 0x200 + ch_num * 0x20 + 0x0c pwm channel counter register pwm_ccnt read-only 0x0 0x200 + ch_num * 0x20 + 0x10 pwm channel update register pwm_cupd write-only -
858 sam4cp [datasheet] 43051e?atpl?08/14 38.7.1 pwm mode register name: pwm_mr address: 0x48008000 access: read/write ? diva, divb: clka, clkb divide factor ? prea, preb values which are not listed in the table must be considered as ?reserved?. 31 30 29 28 27 26 25 24 ? ? ? ? preb 23 22 21 20 19 18 17 16 divb 15 14 13 12 11 10 9 8 ? ? ? ? prea 76543210 diva value name description 0 clk_off clka, clkb clock is turned off 1 clk_div1 clka, clkb clock is clock selected by prea, preb 2 - 255 ? clka, clkb clock is clock selected by prea, preb divided by diva, divb factor value name description 0000 mck master clock 0001 mckdiv2 master clock divided by 2 0010 mckdiv4 master clock divided by 4 0011 mckdiv8 master clock divided by 8 0100 mckdiv16 master clock divided by 16 0101 mckdiv32 master clock divided by 32 0110 mckdiv64 master clock divided by 64 0111 mckdiv128 master clock divided by 128 1000 mckdiv256 master clock divided by 256 1001 mckdiv512 master clock divided by 512 1010 mckdiv1024 master clock divided by 1024
859 sam4cp [datasheet] 43051e?atpl?08/14 38.7.2 pwm enable register name: pwm_ena address: 0x48008004 access: write-only ? chidx: channel id 0 = no effect. 1 = enable pwm output for channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? chid3 chid2 chid1 chid0
860 sam4cp [datasheet] 43051e?atpl?08/14 38.7.3 pwm disable register name: pwm_dis address: 0x48008008 access: write-only ? chidx: channel id 0 = no effect. 1 = disable pwm output for channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? chid3 chid2 chid1 chid0
861 sam4cp [datasheet] 43051e?atpl?08/14 38.7.4 pwm status register name: pwm_sr address: 0x4800800c access: read-only ? chidx: channel id 0 = pwm output for channel x is disabled. 1 = pwm output for channel x is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? chid3 chid2 chid1 chid0
862 sam4cp [datasheet] 43051e?atpl?08/14 38.7.5 pwm interrupt enable register name: pwm_ier address: 0x48008010 access: write-only ? chidx: channel id 0 = no effect. 1 = enable interrupt for pwm channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? chid3 chid2 chid1 chid0
863 sam4cp [datasheet] 43051e?atpl?08/14 38.7.6 pwm interrupt disable register name: pwm_idr address: 0x48008014 access: write-only ? chidx: channel id 0 = no effect. 1 = disable interrupt for pwm channel x. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? chid3 chid2 chid1 chid0
864 sam4cp [datasheet] 43051e?atpl?08/14 38.7.7 pwm interrupt mask register name: pwm_imr address: 0x48008018 access: read-only ? chidx: channel id 0 = interrupt for pwm channel x is disabled. 1 = interrupt for pwm channel x is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? chid3 chid2 chid1 chid0
865 sam4cp [datasheet] 43051e?atpl?08/14 38.7.8 pwm interrupt status register name: pwm_isr address: 0x4800801c access: read-only ? chidx: channel id 0 = no new channel period has been achieved since the last read of the pwm_isr register. 1 = at least one new channel period has been achieved since the last read of the pwm_isr register. note: reading pwm_isr automatically clears chidx flags. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? chid3 chid2 chid1 chid0
866 sam4cp [datasheet] 43051e?atpl?08/14 38.7.9 pwm channel mode register name: pwm_cmr[0..3] address: 0x48008200 [0], 0x48008220 [1], 0x48008240 [2], 0x48008260 [3] access: read/write ? cpre: channel pre-scaler values which are not listed in the table must be considered as ?reserved?. ? calg: channel alignment 0 = the period is left aligned. 1 = the period is center aligned. ? cpol: channel polarity 0 = the output waveform starts at a low level. 1 = the output waveform starts at a high level. ? cpd: channel update period 0 = writing to the pwm_cupdx will modify the duty cycle at the next period start event. 1 = writing to the pwm_cupdx will modify the period at the next period start event. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? ? ? ? ? cpd cpol calg 76543210 ? ? ? ? cpre value name description 0000 mck master clock 0001 mckdiv2 master clock divided by 2 0010 mckdiv4 master clock divided by 4 0011 mckdiv8 master clock divided by 8 0100 mckdiv16 master clock divided by 16 0101 mckdiv32 master clock divided by 32 0110 mckdiv64 master clock divided by 64 0111 mckdiv128 master clock divided by 128 1000 mckdiv256 master clock divided by 256 1001 mckdiv512 master clock divided by 512 1010 mckdiv1024 master clock divided by 1024 1011 clka clock a 1100 clkb clock b
867 sam4cp [datasheet] 43051e?atpl?08/14 38.7.10 pwm channel duty cycle register name: pwm_cdty[0..3] address: 0x48008204 [0], 0x48008224 [1], 0x48008244 [2], 0x48008264 [3] access: read/write only the first 16 bits (internal channel counter size) are significant. ? cdty: channel duty cycle defines the waveform duty cycle. this value must be defined between 0 and cprd (pwm_cprx). 31 30 29 28 27 26 25 24 cdty 23 22 21 20 19 18 17 16 cdty 15 14 13 12 11 10 9 8 cdty 76543210 cdty
868 sam4cp [datasheet] 43051e?atpl?08/14 38.7.11 pwm channel period register name: pwm_cprd[0..3] address: 0x48008208 [0], 0x48008228 [1], 0x48008248 [2], 0x48008268 [3] access: read/write only the first 16 bits (internal channel counter size) are significant. ? cprd: channel period if the waveform is left-aligned, then the output waveform period depends on the counter source clock and can be calculated: ? by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). the resulting period formula will be: ? by using a master clock divided by one of both diva or divb divider, the formula becomes, respectively: or if the waveform is center-aligned, then the output waveform period depends on the counter source clock and can be calculated: ? by using the master clock (mck) divided by an x given prescaler value (with x being 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, or 1024). the resulting period formula will be: ? by using a master clock divided by one of both diva or divb divider, the formula becomes, respectively: or 31 30 29 28 27 26 25 24 cprd 23 22 21 20 19 18 17 16 cprd 15 14 13 12 11 10 9 8 cprd 76543210 cprd xcprd ? ?? mck -------------------------------- crpd diva ? ?? mck ------------------------------------------ crpd divab ? ?? mck ---------------------------------------------- 2 x cprd ? ? ?? mck ----------------------------------------- - 2 cprd diva ? ? ?? mck --------------------------------------------------- - 2 cprd ? divb ? ?? mck --------------------------------------------------- -
869 sam4cp [datasheet] 43051e?atpl?08/14 38.7.12 pwm channel counter register name: pwm_ccnt[0..3] address: 0x4800820c [0], 0x4800822c [1], 0x4800824c [2], 0x4800826c [3] access: read-only ? cnt: channel counter register internal counter value. this register is reset when: ? the channel is enabled (writing chidx in the pwm_ena register). ? the counter reaches cprd value defined in the pwm_cprdx register if the waveform is left aligned. 31 30 29 28 27 26 25 24 cnt 23 22 21 20 19 18 17 16 cnt 15 14 13 12 11 10 9 8 cnt 76543210 cnt
870 sam4cp [datasheet] 43051e?atpl?08/14 38.7.13 pwm channel update register name: pwm_cupd[0..3] address: 0x48008210 [0], 0x48008230 [1], 0x48008250 [2], 0x48008270 [3] access: write-only ? cupd: channel update register this register acts as a double buffer for the period or the duty cycle. this prevents an unexpected waveform when modifying the waveform period or duty-cycle. only the first 16 bits (internal channel counter size) are significant. when cpd field of pwm_cmrx register = 0, the duty-cycle (cdty of pwm_cdtyx register) is updated with the cupd value at the beginning of the next period. when cpd field of pwm_cmrx register = 1, the period (cprd of pwm_cprdx register) is updated with the cupd value at the beginning of the next period. 31 30 29 28 27 26 25 24 cupd 23 22 21 20 19 18 17 16 cupd 15 14 13 12 11 10 9 8 cupd 76543210 cupd
871 sam4cp [datasheet] 43051e?atpl?08/14 39. segment liquid crystal display controller (slcdc) 39.1 description the segment liquid crystal display controller (slcdc) can drive a monochrome passive liquid crystal display (lcd) with up to 5 common terminals and up to 46 segment terminals. an lcd consists of several segments (pixels or complete symbols) which can be visible or invisible. a segment has two electrodes with liquid crystal between them. when a voltage above a threshold voltage is applied across the liquid crystal, the segment becomes visible. the voltage must alternate to avoid an electrophoresis effect in the liquid crystal, which degrades the display. hence the waveform across a segment must not have a dc component. the slcdc is programmable to support many different requirements such as: ? adjusting the driving time of the lcd pads in order to save power and increase the controllability of the dc offset. ? driving smaller lcd (down to 1 common by 1 segment). ? adjusting the slcdc frequency in order to obtain the best compromise between frequency and consumption and adapt it to the lcd driver. ? assigning the segments in a user defined pattern to use of the digital functions multiplexed on these pins. note: please check slcdc available signals in the main block diagram figure 2-1 . 39.1.1 definition of terms. 39.2 embedded characteristics the slcdc provides the following capabilities: ? display capacity: up to 46 segments and 5 common terminals. ? support from static to 1/6 duty. ? support static, 1/2, 1/3 bias. ? two lcd supply sources: ? internal (on-chip lcd power supply). ? external. ? lcd output voltage software selectable from 2.4v to vddin in 16 steps. (control embedded in the supply controller). ? flexible selection of frame frequency. ? two interrupt sources: end of frame and disable. ? versatile display modes. ? equal source and sink capability to maximize lcd life time. ? segment and common pins not needed for driving the display can be used as ordinary i/o pins. ? segments layout can be fully defined by user to optimize usage of multiplexed digital functions. ? latching of display data gives full freedom in register updates. ? power saving modes for extremely low power consumption. ? register write protection table 39-1. list of terms term description lcd a passive display panel with terminals leading directly to a segment. segment the least viewing element (pixel) which can be on or off. common(s) denotes how many segments are connected to a segment terminal. duty 1/(number of common terminals on an actual lcd display). bias 1/(number of voltage levels used driving a lcd display -1). frame rate number of times the lcd segments are energized per second.
872 sam4cp [datasheet] 43051e?atpl?08/14 39.3 block diagram figure 39-1. slcdc block diagram clk slcdc a p b b u s 1/3 v ddlcd 1/2 v ddlcd 2/3 v ddlcd v ddlcd v ddlcd clock multiplexer prescaler divide by 1 to 8 slcdc_dr slcdc_frr slck/ 8 div presc slck slcdc_{l,m}memr0 slck/1024 timing generation /2 /16 com./rate uniformizer comsel display frame buffer user frame buffer comsel, lpmode, bias lcdblkfreq, dispmode endframe it generation disable buffer_on endframe bufftime, lcdblkfreq com0 com1 analog buffers slcdc_mr com4 com5 slcdc_cr slcdc_ier slcdc_idr slcdc_imr slcdc_isr on enable, disable, swrst comsel, segsel buffer_on on-chip resistor ladder for 1/2 bias 1/2 slcdc_sr ena bias,bufftime, lpmode on-chip resistor ladder for 1/3 bias 2/3 1/3 analog switch array seg0 seg1 seg2 seg3 seg4 seg5 seg45 seg46 seg47 seg48 seg49 mux lcd seg waveform generator output decoder lcd com waveform generator dispmode, segsel,lcdn bias gnd rr gnd rrr seg x (com->1) slcdc_smr lcdn analog/digital pad control to segn pad buffers lcdn segsel ena analog/digital pad control to comn pad buffers comsel ena slcdc_{l,m}memr1
873 sam4cp [datasheet] 43051e?atpl?08/14 39.4 i/o lines description 39.5 product dependencies 39.5.1 i/o lines the pins used for interfacing the slcd controller may be multiplexed with pio lines. please refer to product block diagram. if i/o lines of the slcd controller are not used by the application, they can be used for other purposes by the pio controller. by default (slcdc_smr0/1 registers cleared) the assignment of the segment controls and commons are automatically done depending on comsel and segsel in slcdc_mr. as example, if 10 segments are programmed in the segsel field, they are automatically assigned to seg[9:0 ] whereas remaining seg pins are automatically selected to be driven by the multiplexed digital functions. anyway, the user can define a new layout pattern for the segment assignment by programming the slcdc_smr0/1 registers in order to optimize the usage of multiplexed digital function. if at least 1 bit is set in slcdc_smr0/1 registers, the corresponding i/o line will be driven by an lcd segment whereas any cleared bit of this register will select the corresponding multiplexed digital function. table 39-2. i/o lines description name description type seg [3:47], seg49 segments control signals output com [0:4] commons control signals output table 39-3. i/o lines instance signal i/o line peripheral slcdc com0 pa0 x1 slcdc com1 pa1 x1 slcdc com2 pa2 x1 slcdc com3 pa3 x1 slcdc com4/ad1 pa4 x1 slcdc seg3 pa9 x1 slcdc seg4 pa10 x1 slcdc seg5 pa11 x1 slcdc seg6/ad0 pa12 x1 slcdc seg7 pa13 x1 slcdc seg8 pa14 x1 slcdc seg9 pa15 x1 slcdc seg10 pa16 x1 slcdc seg11 pa17 x1 slcdc seg12 pa18 x1 slcdc seg13 pa19 x1 slcdc seg14 pa20 x1 slcdc seg15 pa21 x1
874 sam4cp [datasheet] 43051e?atpl?08/14 slcdc seg16 pa22 x1 slcdc seg17 pa23 x1 slcdc seg18 pa24 x1 slcdc seg19 pa25 x1 slcdc seg20 pa26 x1 slcdc seg21 pa27 x1 slcdc seg22 pa28 x1 slcdc seg23 pa29 x1 slcdc seg24 pb6 x1 slcdc seg25 pb7 x1 slcdc seg26 pb8 x1 slcdc seg27 pb9 x1 slcdc seg28 pb10 x1 slcdc seg29 pb11 x1 slcdc seg30 pb12 x1 slcdc seg31/ad3 pb13 x1 slcdc seg32 pb14 x1 slcdc seg33 pb15 x1 slcdc seg34 pb16 x1 slcdc seg35 pb17 x1 slcdc seg36 pb18 x1 slcdc seg37 pb19 x1 slcdc seg38 pb20 x1 slcdc seg39 pb21 x1 slcdc seg40 pb22 x1 slcdc seg41/ad4 pb23 x1 slcdc seg42 pb24 x1 slcdc seg43 pb25 x1 slcdc seg44 pb26 x1 slcdc seg45 pb27 x1 slcdc seg46 pb28 x1 slcdc seg47 pb29 x1 slcdc seg49/ad5 pb31 x1 table 39-3. i/o lines (continued)
875 sam4cp [datasheet] 43051e?atpl?08/14 39.5.2 power management the slcd controller is clocked by the slow clock (slck). all the timings are ba sed upon a typical value of 32 khz for slck. the lcd segment/common pad buffers are supplied by the vddlcd domain. 39.5.3 interrupt sources the slcd controller interrupt line is connected to one of the internal sources of the interrupt controller. using the slcd controller interrupt requires prior programming of the interrupt controller. 39.5.4 number of segments and commons the product, embeds 46 segments and 5 commons. 39.6 functional description the use of the slcdc comprises three phases of functionality: initialization sequence, display phase and disable sequence. ? initialization sequence: 1. select the lcd supply source in the shutdown controller. ? internal: the on-chip lcd power supply is selected. ? external: the external supply source has to be between 2.5 to 3.6v. 2. select the clock division (slcdc_frr) to use a proper frame rate. 3. enter the number of common and segments terminals (slcdc_mr). 4. select the bias in compliance with the lcd manufacturer data sheet (slcdc_mr). 5. enter buffer driving time (slcdc_mr). 6. define the segments remapping pattern if required (slcdc_smr0/1). ? during the display phase: 1. data may be written at any time in the slcdc memory, they are automatically latched and displayed at the next lcd frame. 2. it is possible to: ? adjust contrast. ? adjust the frame frequency. ? adjust buffer driving time. ? reduce the slcdc consumption by entering in low-power waveform at any time. ? use the large set of display features such as blinking, inverted blink, etc. ? disable sequence: there are two ways to disable the slcdc. 1. by using the slcdc_cr [lcddis] bit (recommended method).in this case, slcdc configuration and memory content are maintained. 2. by using the swrst (software reset) bit that acts like a hardware reset for slcdc only. table 39-4. peripheral ids instance id slcdc 32
876 sam4cp [datasheet] 43051e?atpl?08/14 39.6.1 clock generation 39.6.1.1 block diagram figure 39-2. clock generation block diagram 39.6.2 waveform generation 39.6.2.1 static duty and bias this kind of display is driven with the waveform shown in figure 39-3 . seg0 - com0 is the voltage across a segment that is on, and seg1 - com0 is the voltage across a segment that is off. figure 39-3. driving an lcd with one common terminal clk slcdc clk slcdc prescaler divider (1 t o 8) slck /2 /16 slck/8 slck/1024 com./rate uniformizer slcdc_frr slcdc_mr lpmode comsel segsel bufftime div presc clock mux comsel endframe timing generation lcd com waveform generator lcd seg waveform generator buffer_on blink period com + seg waveform generator buffer driving time management blinking generator slcdc_dr lcdblkfreq v ddlcd gnd v ddlcd gnd v ddlcd gnd -v ddlcd frame frame v ddlcd gnd v ddlcd gnd gnd seg1 com0 seg1 - com0 frame frame seg0 com0 seg0 - com0
877 sam4cp [datasheet] 43051e?atpl?08/14 39.6.2.2 1/2 duty and 1/2 bias for an lcd with two common terminals (1/2 duty) a more complex waveform must be used to control segments individually. although 1/3 bias can be selected, 1/2 bias is most common for th ese displays. in the waveform shown in figure 39-4 , seg0 - com0 is the voltage across a segment that is on, and seg0 - com1 is the voltage across a segment that is off. figure 39-4. driving an lcd with two common terminals 39.6.2.3 1/3 duty and 1/3 bias 1/3 bias is usually recommended for an lcd with three common terminals (1/3 duty). in the waveform shown in figure 39-5 , seg0 - com0 is the voltage across a segment that is on and seg0-com1 is the voltage across a segment that is off. figure 39-5. driving an lcd with three common terminals v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd -1 / 2 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd v ddlcd 1 / 2 v ddlcd gnd -1 / 2 v ddlcd -v ddlcd seg0 com1 seg0 - com1 frame frame frame frame frame frame frame frame v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com1 seg0 - com1
878 sam4cp [datasheet] 43051e?atpl?08/14 39.6.2.4 1/4 duty and 1/3 bias 1/3 bias is optimal for lcd displays with four common terminals (1/4 duty). in the waveform shown in figure 39-6 , seg0 - com0 is the voltage across a segment that is on and seg0 - com1 is the voltage across a segment that is off. figure 39-6. driving an lcd with four common terminals 39.6.2.5 low-power waveform to reduce toggle activity and hence power consumption, a low-power waveform can be selected by writing lpmode to one. the default and low-power waveform is shown in figure 39-7 for 1/3 duty and 1/3 bias. for other selections of duty and bias, the effect is similar. figure 39-7. default and low-power waveform note: refer to the lcd specification to verify that low-power waveforms are supported. frame frame frame frame v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com1 seg0 - com1 frame frame frame frame v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0 v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd v ddlcd 2 / 3 v ddlcd 1 / 3 v ddlcd gnd - 1 / 3 v ddlcd - 2 / 3 v ddlcd -v ddlcd seg0 com0 seg0 - com0
879 sam4cp [datasheet] 43051e?atpl?08/14 39.6.2.6 frame rate the frame rate register (slcdc_frr) enables the generation of the frequency used by the slcdc. it is done by a prescaler (division by 8, 16, 32, 64, 128, 256, 512 and 1024) followed by a finer divider (division by 1, 2, 3, 4, 5, 6, 7 or 8 ). to calculate the needed frame frequency, the equation below must be used: where: f slck = slow clock frequency f frame = frame frequency presc = prescaler value (8, 16, 32, 64, 128, 256, 512 or 1024) div = divider value (1, 2, 3, 4, 5, 6, 7, or 8) ncom = depends of number of commons and is defined in table 39-5 . ncom is automatically provided by the slcdc. as example, if comsel is programmed to 0 (1 common terminal on display device), the slcdc introduces a divider by 16 so that ncom = 16. if comsel is programmed to 3 (3 common terminals on display device), the slcdc introduces a divider by 5 so that the ncom remains close to 16 (frame rate is uniformized whatever the number of driven commons). 39.6.2.7 buffer driving time intermediate voltage levels are generated from buffer drivers. the buffers are active the amount of time specified by buftime[3:0] in slcdc_mr, then buffers are bypassed. shortening the drive time will reduce power consumption, but displays with high internal resistance or capacitance may need longer drive time to achieve sufficient contrast. example for bias = 1/3. table 39-5. ncom number of commons ncom uniformizer divider 11616 2168 3155 4164 5153 6183 f frame f s lck presc div ncom ?? ?? ---------------------------------------------------------------- =
880 sam4cp [datasheet] 43051e?atpl?08/14 figure 39-8. buffer driving 39.6.3 number of commons, segments and bias it is important to note that the selection of the number of commons, segments and the bias can be programmed when the slcdc is disabled. 39.6.4 slcdc memory figure 39-9. memory management when a bit in the display memory (slcdc_lmemrx and slcdc_mmemrx registers) is written to one, the corresponding segment is energized (on), and non-energized when a bit in the display memory is written to zero. at the beginning of each common, the display buffer is updated. the value of the previous common is latched in the display memory (its value is transferred from the user buffer to the frame buffer). slcdc_mr bufftime v ddlcd r r r 2/3 v ddlcd 1/3 v ddlcd load data fro m the user buff to the disp buff displa y data previousl y loaded fro m the user buffer to the disp buffer load data fro m the user buffer to the disp buffer displa y data previousl y loaded fro m the user buffer to the disp buffer load data fro m the user buffer to the disp buffer displa y data previousl y loaded fro m the user buffer to the disp buffer com0 ti m e slot com1 ti m e slot com2 ti m e slot com0 com1 com2
881 sam4cp [datasheet] 43051e?atpl?08/14 the advantages of this solution are: ? ability to access the user buffer at any time in the frame, in any display mode and even in low-power waveform. ? ability to change only one pixel without reloading the picture. 39.6.5 display features in order to improve the flexibility of slcdc the following set of display modes are embedded: 1. force mode off: all pixels are turned off and the memory content is kept. 2. force mode on: all pixels are turned on and the memory content is kept. 3. inverted mode: all pixels are set in the inverted state as defined in slcdc memory and the memory content is kept. 4. two blinking modes: ? standard blinking mode: all pixels are alternately turned off to the predefined state in slcdc memory at lcdblkfreq frequency. ? inverted blinking mode: all pixels are alternately turned off to the predefined opposite state in slcdc memory at lcdblkfreq frequency. 5. buffer swap mode: all pixels are alternatively assigned to the state defined in the user buffer then to the state defined in the display buffer. 39.6.6 buffer swap mode this mode allows to assign all pixels to two states alternatively without reloading the user buffer at each change. the means to alternatively display two states is as follows: 1. initially, the slcdc must be in normal mode or in a standard blinking mode. 2. data corresponding to the first pixel state is written in the user buffer (through the slcdc_mem registers). 3. wait two endframe events (to be sure that the user buffer is entirely transferred in the display buffer). 4. slcdc_dr must be programmed with dispmode = 6 (user buffer only load mode). this mode blocks the automatic transfer from the user buffer to the display buffer. 5. wait endframe event. (the display mode is internally updated at the beginning of each frame). 6. data corresponding to the second pixel state is written in the user buffer (through the slcdc_mem registers). so, now the first pixel state is in the display buffer and the second pixel state is in the user buffer. 7. slcdc_dr must be programmed with dispmode = 7 (buffer swap mode) and lcdblkfreq must be programmed with the wanted blinking frequency (if not previously done). now, each state is alternatively displayed at lcdblkfreq frequency. except for the phase dealing with the storage of the two display states, the management of the buffer swap mode is the same as the standard blinking mode. 39.6.7 disabling the slcdc there are two ways to disable the slcdc: 1. by using the slcdc_cr [lcddis] bit (recommended method). in this case, slcdc configuration and memory content are maintained. 2. by using the swrst (software reset) bit that acts like a hardware reset for slcdc only. both methods are described in the following sections.
882 sam4cp [datasheet] 43051e?atpl?08/14 39.6.7.1 disable bit the lcddis bit in the slcdc_cr can be set at any time. when the lcd disable command is activated during a frame, the slcdc is not immediately stopped (see figure 39-10 ). the next frame will be generated in ?all ground? mode (where by all commons and segments will be tied to ground). at the end of this ?all ground? frame, the disable interrupt is asserted if the bit dis is set in the slcdc_imr. the slcdc is now disabled. figure 39-10. disabling sequence 39.6.7.2 software reset when the slcdc software reset command is activated during a frame it is immediately processed and all commons and segments are tied to ground. note that in the case of a software reset, the disable interrupt is not asserted. figure 39-11. software reset end of frame interrupt common disable example for three commons ena bit slcdc interrupt v ddlcd -v ddlcd gnd 1/3 -1/3 disable command the common is tied to ground command processing begins the disable command is activated slcdc disabled end of frame interrupt common v ddlcd -v ddlcd gnd 1/3 -1/3 sw reset example for three commons sw reset command the common is immediatly tied to ground the sw reset command is activated
883 sam4cp [datasheet] 43051e?atpl?08/14 39.6.8 flowchart figure 39-12. slcdc flow chart enter/exit from low-power wave form? change the frame rate ? no no no lpmode in slcdc_mr presc + div in slcdc_frr buftime in slcdc_mr disable the slcdc ? sw reset ? swrst in slcdc_cr lcddis in slcdc_cr disable interrupt? no dis in slcdc_isr ena bit = 0? no ena in slcdc_sr no blink? change/update the display mode ( dispmode in slcdc_dr) no - normal mode - force off - force on - inverted mode change/update the display mode ( dispmode in slcdc_dr) - blinking mode - inverted blinking mode change/update the blinking frequency ( lcdblkfreq in slcdc_dr) change the power comsumption ? no ena = 1? ena in slcdc_sr no update the displayed data? write the new data in the slcdc_mem no no update/change the display mode? initialization supply source (internal or external) number of com (comsel in slcdc_mr) number of seg ( segsel in slcdc_mr) frame rate (( presc + div ) in slcdc_frr) buff on time ( buftime in slcdc_mr) bias ( bias in slcdc_mr) enables the slcdc lcden in slcdc_mr end start
884 sam4cp [datasheet] 43051e?atpl?08/14 39.6.9 user buffer organization the pixels to be displayed are written into slcdc_lmemrx and slcdc_mmemrx registers. there are up to two 32-bit registers for each common terminal. table 39-6 provides the address mapping of all commons/segments to be displayed. if the segment map registers (slcdc_smr0/1) are cleared and the number of segments to handle (segsel field in slcdc_mr) is lower or equal to 32, the registers slcdc_mmemrx are not required to be programmed and can be left cleared (default value). in case segments are remapped, the slcdc_mmemrx registers are not required to be programmed if slcdc_smr1 register is cleared (i.e. no segment remapped on seg32 to seg49 i/o pins). in this case slcdc_mmemrx registers must be cleared. in the same way if all segments are remapped on the upper part of the seg terminals (seg32 to seg49) there is no need to program slcdc_lmemrx registers (they must be cleared). when segment remap is used (slcdc_smr0/1 registers differ from 0), the unmapped segments must be kept cleared to limit internal signal switching. 39.6.10 segments mapping function by default the segments pins (seg0:49 ) are automatically assigned according to the segsel configuration in the slcdc_mr. the unused seg i/o pins are forced to be driven by a digital peripheral or can be used as i/o through the pio controller. the automatic assignment is performed if the segment mapping function is not used (slcdc_smr0/1 registers are cleared). the following table provides such assignments. table 39-6. commons/segments address mapping seg0 -- seg31 seg32 -- seg49 memory address slcdc_mmemr5 slcdc_lmemr5 com5 com5 x -- x x-- x 0x22c 0x228 slcdc_mmemr4 slcdc_lmemr4 com4 com4 x -- x x-- x 0x224 0x220 slcdc_mmemr3 slcdc_lmemr3 com3 com3 x -- x x-- x 0x21c 0x218 slcdc_mmemr2 slcdc_lmemr2 com2 com2 x -- x x-- x 0x214 0x210 slcdc_mmemr1 slcdc_lmemr1 com1 com1 x -- x x-- x 0x20c 0x208 slcdc_mmemr0 slcdc_lmemr0 com0 com0 x -- x x-- x 0x204 0x200 segsel i/o port in use as segment driver i/o port pin if slcdc_smr0/1=0 0 seg0 seg1:49 1 seg0:1 seg2:49 ... ... ... 48 seg0:48 seg49 49 seg0:49 none
885 sam4cp [datasheet] 43051e?atpl?08/14 programming is straightforward in this mode but it prevents flexibility of use of the digital peripheral multiplexed on seg0:49 especially when the number of segments to drive is close to the maximum (50). for example, if the segsel is set to 48, only the digital peri pheral associated to seg49 ca n be used and none of the other digital peripherals multiplexed on seg0:48 i/o can be used. to offer a flexible selection of digital peripherals multipl exed on seg0:49 the user can manually configure the seg i/o pins to be driven by the slcdc. this is done by programming the slcdc_smr0/1 registers. as soon as their values differ from 0 the segment remapping mode is used. when configuring a logic 1 at index n (n = 0..49) in slcdc_smr0/1 registers, the slcdc forces the segn i/o pin to be driven by a segment waveform. in this mode the segsel field configuration value in slcdc_mr is ignored. in remapping mode the software dispatches the pixels into slcdc_lmemrx or slcdc_mmemrx according to what is programmed in slcdc_smr0/1 registers. figure 39-13. segments remapping example co m 0 co m 1 seg0 seg1 seg2 seg3 lcd displa y panel microcontroller com0 com1 com5 seg0 seg1 seg2 seg3 seg4 seg28 seg29 seg30 dig0 dig1 dig5 dig6 dig7 dig8 dig9 dig10 dig11 dig12 dig13 comsel=1 segsel=3 slcdc_smr0=0 slcdc_smr1=0 slcdc_lmemr0=0 x 5 slcdc_lmemr1=0 x a co m 0 co m 1 seg0 seg1 seg2 seg3 lcd displa y panel microcontroller com0 com1 com5 seg0 seg1 seg2 seg3 seg4 seg28 seg29 seg30 dig0 dig1 dig5 dig6 dig7 dig8 dig9 dig10 dig11 dig12 dig13 comsel=1 segsel=3 slcdc_smr0=0 x 8000_0002 slcdc_smr1=0 x 0000_0003 slcdc_lmemr0=0 x 2, slcdc_mmemr0=0 x 1 slcdc_lmemr1=0 x 8000_0000 slcdc_mmemr1=0 x 0000_0002 default segment pins assigments user remapped segment pins assigments user config. default config. unusable digital functions. dig10 dig11 dig12 dig13 lcd panel config. direct i m age buffer. pre-processed i m age buffer. dig6 dig8 dig9 dig10
886 sam4cp [datasheet] 43051e?atpl?08/14 39.6.11 register write protection to prevent any single software error from corrupting slcdc behavior, certain registers in the address space can be write-protected by setting the wpen bit in the ?slcdc write protection mode register? (slcdc_wpmr). if a write access to a write-protected register is detected, the wpvs bit in the ?slcdc write protection status register? (slcdc_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the slcdc_wpsr. the following registers can be write-protected: ?slcdc mode register? on page 889 ?slcdc frame rate register? on page 891 ?slcdc display register? on page 892 ?slcdc segment map register 0? on page 899 ?slcdc segment map register 1? on page 900 39.7 waveform specifications 39.7.1 dc characteristics refer to the dc characteristics section of the product datasheet. 39.7.2 lcd contrast the peak value (v ddlcd ) on the output waveform determines the lcd contrast. v ddlcd is controlled by software in 16 steps from 2.4v to vddin. this is a function of the supply controller.
887 sam4cp [datasheet] 43051e?atpl?08/14 39.8 segment lcd controller (slcdc) user interface table 39-7. register mapping offset register name access reset 0x0 slcdc control register slcdc_cr write-only - 0x4 slcdc mode register slcdc_mr read/write 0x0 0x8 slcdc frame rate register slcdc_frr read/write 0x0 0xc slcdc display register slcdc_dr read/write 0x0 0x10 slcdc status register slcdc_sr read-only 0x0 0x20 slcdc interrupt enable register slcdc_ier write-only - 0x24 slcdc interrupt disable register slcdc_idr write-only - 0x28 slcdc interrupt mask register slcdc_imr read-only - 0x2c slcdc interrupt status register slcdc_isr read-only 0x0 0x30 slcdc segment map register 0 slcdc_smr0 read/write 0x0 0x34 slcdc segment map register 1 slcdc_smr1 read/write 0x0 0x38 - 0xe4 reserved - - - 0xe4 slcdc write protection mode register slcdc_wpmr read/write 0x0 0xe8 slcdc write protection status register slcdc_wpsr read-only 0x0 0xec - 0xf8 reserved - - - 0xfc reserved - - - 0x200 + com*0x8 + 0x0 slcdc lsb memory register slcdc_lmemr read/write 0x0 0x200 + com*0x8 + 0x4 slcdc msb memory register slcdc_mmemr read/write 0x0
888 sam4cp [datasheet] 43051e?atpl?08/14 39.8.1 slcdc control register name: slcdc_cr address: 0x4003c000 access: write-only reset: 0x00000000 ? lcden: enable the lcdc 0 = no effect. 1 = the slcdc is enabled. ? lcddis: disable lcdc 0 = no effect. 1 = the slcdc is disabled. note: lcddis is processed at the beginning of the next frame. ? swrst: software reset 0 = no effect. 1 = equivalent to a power-up reset. when this command is performed, the slcdc immediately ties all segments end commons lines to values corresponding to a ?ground voltage?. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? swrst ? lcddis lcden
889 sam4cp [datasheet] 43051e?atpl?08/14 39.8.2 slcdc mode register name: slcdc_mr address: 0x4003c004 access: read/write reset: 0x00000000 this register can only be written if the wpen bit is cleared in the ?slcdc write protection mode register? . ? comsel: selection of the number of commons (for safety reasons, can be configured when slcdc is disabled). ? segsel: selection of the number of segments (for safety reasons, can be configured when slcdc is disabled). segsel must be programmed with the number of segments of the display panel minus 1. if segment remapping function is not used (i.e. slcdc_smrx equal 0) the segn [n = 0..49] i/o pins where n is greater than segsel are forced to be driven by digital function. when segments remapping function is used, segn pins are driven by slcdc only if corresponding pixeln configuration bit is set in slcdc_smr1/0 registers. ? bias: lcd display configuration (for safety reasons, can be configured when slcdc is disabled). 31 30 29 28 27 26 25 24 ??????? lpmode 23 22 21 20 19 18 17 16 ? ? bias buftime 15 14 13 12 11 10 9 8 ? ? segsel 76543210 ? ? ? ? ? comsel value name description 0x0 com_0 com0 is driven by slcdc, com1:4 are driven by digital function 0x1 com_0to1 com0:1 are driven by slcdc, com2:4 are driven by digital function 0x2 com_0to2 com0:2 are driven by slcdc, com3:4 are driven by digital function 0x3 com_0to3 com0:3 are driven by slcdc, com4 is driven by digital function 0x4 com_0to4 com0:4 are driven by slcdc, no com pin driven by digital function value name description 0x0 static static 0x1 bias_1_2 bias 1/2 0x2 bias_1_3 bias 1/3
890 sam4cp [datasheet] 43051e?atpl?08/14 ? lpmode: low-power mode (processed at beginning of next frame). 0 = normal mode. 1 = low-power waveform is enabled. ? buftime: buffer on-time (processed at beginning of next frame). value name description 0x0 off nominal drive time is 0% of slck period 0x1 x2_slck_period nominal drive time is 2 periods of slck clock 0x2 x4_slck_period nominal drive time is 4 periods of slck clock 0x3 x8_slck_period nominal drive time is 8 periods of slck clock 0x4 x16_slck_period nominal drive time is 16 periods of slck clock 0x5 x32_slck_period nominal drive time is 32 periods of slck clock 0x6 x64_slck_period nominal drive time is 64 periods of slck clock 0x7 x128_slck_period nominal drive time is 128 periods of slck clock 0x8 percent_50 nominal drive time is 50% of slck period 0x9 percent_100 nominal drive time is 100% of slck period
891 sam4cp [datasheet] 43051e?atpl?08/14 39.8.3 slcdc frame rate register name: slcdc_frr address: 0x4003c008 access: read/write reset: 0x00000000 this register can only be written if the wpen bit is cleared in the ?slcdc write protection mode register? . ? presc: clock prescaler (processed at beginning of next frame). ? div: clock division (processed at beginning of next frame). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ????? div 76543210 ? ? ? ? ? presc value name description 0x0 slck_div8 slow clock is divided by 8 0x1 slck_div16 slow clock is divided by 16 0x2 slck_div32 slow clock is divided by 32 0x3 slck_div64 slow clock is divided by 64 0x4 slck_div128 slow clock is divided by 128 0x5 slck_div256 slow clock is divided by 256 0x6 slck_div512 slow clock is divided by 512 0x7 slck_div1024 slow clock is divided by 1024 value name description 0x0 presc_clk_div1 clock output from prescaler is divided by 1 0x1 presc_clk_div2 clock output from prescaler is divided by 2 0x2 presc_clk_div3 clock output from prescaler is divided by 3 0x3 presc_clk_div4 clock output from prescaler is divided by 4 0x4 presc_clk_div5 clock output from prescaler is divided by 5 0x5 presc_clk_div6 clock output from prescaler is divided by 6 0x6 presc_clk_div7 clock output from prescaler is divided by 7 0x7 presc_clk_div8 clock output from prescaler is divided by 8
892 sam4cp [datasheet] 43051e?atpl?08/14 39.8.4 slcdc display register name: slcdc_dr address: 0x4003c00c access: read/write reset: 0x00000000 this register can only be written if the wpen bit is cleared in the ?slcdc write protection mode register? . ? dispmode: display mode register (processed at beginning of next frame). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 lcdblkfreq 76543210 ? ? ? ? ? dispmode value name description 0x0 normal normal mode: latched data are displayed. 0x1 force_off force off mode: all pixels are invisible. (the slcdc memory is unchanged). 0x2 force_on force on mode: all pixels are visible. (the slcdc memory is unchanged). 0x3 blinking blinking mode: all pixels are alternately turned off to the predefined state in slcdc memory at lcdblkfreq frequency. (the slcdc memory is unchanged). 0x4 inverted inverted mode: all pixels are set in the inverted state as defined in slcdc memory. (the slcdc memory is unchanged). 0x5 inverted_blink inverted blinking mode: all pixels are alternately turned off to the predefined opposite state in slcdc memory at lcdblkfreq frequency. (the slcdc memory is unchanged). 0x6 user_buffer_load user buffer only load mode: blocks the automatic transfer from user buffer to display buffer. 0x7 buffers_swap buffer swap mode: all pixels are alternatively assigned to the state defined in the user buffer, then to the state defined in the display buffer at lcdblkfreq frequency.
893 sam4cp [datasheet] 43051e?atpl?08/14 ? lcdblkfreq: lcd blinking frequency selection (processed at beginning of next frame). blinking frequency = frame frequency/lcdblkfreq[7:0]. note: 0 written in lcdblkfreq stops blinking.
894 sam4cp [datasheet] 43051e?atpl?08/14 39.8.5 slcdc status register name: slcdc_sr address: 0x4003c010 access: read-only ? ena: enable status (automatically set/reset) . 0 = the slcdc is disabled. 1 = the slcdc is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????ena
895 sam4cp [datasheet] 43051e?atpl?08/14 39.8.6 slcdc interrupt enable register name: slcdc_ier address: 0x4003c020 access: write-only ? endframe: end of frame interrupt enable 0 = no effect. 1 = enables the corresponding interrupt. ? dis: slcdc disable completion interrupt enable 0 = no effect. 1 = enables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? dis ? endframe
896 sam4cp [datasheet] 43051e?atpl?08/14 39.8.7 slcdc interrupt disable register name: slcdc_idr address: 0x4003c024 access: write-only ? endframe: end of frame interrupt disable 0 = no effect. 1 = disables the corresponding interrupt. ? dis: slcdc disable completion interrupt disable 0 = no effect. 1 = disables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? dis ? endframe
897 sam4cp [datasheet] 43051e?atpl?08/14 39.8.8 slcdc interrupt mask register name: slcdc_imr address: 0x4003c028 access: read-only ? endframe: end of frame interrupt mask 0 = the corresponding interrupt is not enabled. 1 = the corresponding interrupt is enabled. ? dis: slcdc disable completion interrupt mask 0 = the corresponding interrupt is not enabled. 1 = the corresponding interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? dis ? endframe
898 sam4cp [datasheet] 43051e?atpl?08/14 39.8.9 slcdc interrupt status register name: slcdc_isr address: 0x4003c02c access: read-only ? endframe: end of frame interrupt status 0 = no end of frame occurred since the last read. 1 = end of frame occurred since the last read. ? dis: slcdc disable completion interrupt status 0 = the slcdc is enabled. 1 = the slcdc is disabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? dis ? endframe
899 sam4cp [datasheet] 43051e?atpl?08/14 39.8.10 slcdc segment map register 0 name: slcdc_smr0 address: 0x4003c030 access: read/write this register can only be written if the wpen bit is cleared in the ?slcdc write protection mode register? . ? lcdx: lcd segment mapped on segx i/o pin (for safety reasons, can be configured when slcdc is disabled). 0 = the corresponding i/o pin will be driven either by slcdc or digital function acc ording to segsel field configuration in the slcdc_mr. 1 = an lcd segment will be driven on corresponding i/o pin. 31 30 29 28 27 26 25 24 lcd31 lcd30 lcd29 lcd28 lcd27 lcd26 lcd25 lcd24 23 22 21 20 19 18 17 16 lcd23 lcd22 lcd21 lcd20 lcd19 lcd18 lcd17 lcd16 15 14 13 12 11 10 9 8 lcd15 lcd14 lcd13 lcd12 lcd11 lcd10 lcd9 lcd8 76543210 lcd7 lcd6 lcd5 lcd4 lcd3 lcd2 lcd1 lcd0
900 sam4cp [datasheet] 43051e?atpl?08/14 39.8.11 slcdc segment map register 1 name: slcdc_smr1 address: 0x4003c034 access: read/write this register can only be written if the wpen bit is cleared in the ?slcdc write protection mode register? . ? lcdx: lcd segment mapped on segx i/o pin (for safety reasons, can be configured when slcdc is disabled). 0 = the corresponding i/o pin will be driven either by slcdc or digital function acc ording to segsel field configuration in the slcdc_mr. 1 = an lcd segment will be driven on corresponding i/o pin. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? ? ? ? lcd49 lcd48 15 14 13 12 11 10 9 8 lcd47 lcd46 lcd45 lcd44 lcd43 lcd42 lcd41 lcd40 76543210 lcd39 lcd38 lcd37 lcd36 lcd35 lcd34 lcd33 lcd32
901 sam4cp [datasheet] 43051e?atpl?08/14 39.8.12 slcdc write protection mode register name: slcdc_wpmr address: 0x4003c0e4 access: read/write ? wpen: write protection enable 0 = disables the write protection if wpkey corresponds to 0x4c4344 (?lcd? in ascii). 1 = enables the write protection if wpkey corresponds to 0x4c4344 (?lcd? in ascii). see section 39.6.11 ?register write protection? for the list of registers which can be protected. ? wpkey: write protection key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x4c4344 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
902 sam4cp [datasheet] 43051e?atpl?08/14 39.8.13 slcdc write protection status register name: slcdc_wpsr address: 0x4003c0e8 access: read-only ? wpvs: write protection violation status 0 = no write protection violation has occurred since the last read of the slcdc_wpsr. 1 = a write protection violation has occurred since the last read of the slcdc_wpsr. if this violation is an unauthorized attem pt to write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
903 sam4cp [datasheet] 43051e?atpl?08/14 39.8.14 slcdc lsb memory register name: slcdc_lmemrx [x = 0..5] address: 0x4003c200 [0], 0x4003c208 [1], 0x4003c210 [2], 0x4003c218 [3], 0x4003c220 [4], 0x4003c228 [5] access: read/write ? lpixel: lsb pixels pattern associated to comx terminal 0 = the pixel associated to comx terminal is not visible (if non inverted display mode is used). 1 = the pixel associated to comx terminal is visible (if non inverted display mode is used). note: lpixel[n] (n = 0..31) drives segn terminal. 31 30 29 28 27 26 25 24 lpixel 23 22 21 20 19 18 17 16 lpixel 15 14 13 12 11 10 9 8 lpixel 76543210 lpixel
904 sam4cp [datasheet] 43051e?atpl?08/14 39.8.15 slcdc msb memory register name: slcdc_mmemrx [x = 0..5] address: 0x4003c204 [0], 0x4003c20c [1], 0x4003c214 [2], 0x4003c21c [3], 0x4003c224 [4], 0x4003c22c [5] access: read/write ? mpixel: msb pixels pattern associated to comx terminal 0 = the pixel associated to comx terminal is not visible (if non inverted display mode is used). 1 = the pixel associated to comx terminal is visible (if non inverted display mode is used). note: mpixel[n] (n = 32..49) drives segn terminal. 31 30 29 28 27 26 25 24 mpixel 23 22 21 20 19 18 17 16 mpixel 15 14 13 12 11 10 9 8 mpixel 76543210 mpixel
905 sam4cp [datasheet] 43051e?atpl?08/14 40. analog-to-digital converter (adc) 40.1 description the adc is based on a 10-bit analog-to-digital converter (adc) managed by an adc controller. refer to figure 40-1, "analog-to-digital converter block diagram" . it also integrates an 8-to-1 analog multiplexer, making possible the analog-to-digital conversions of 8 analog lines. the conversions extend from 0v to the voltage carried on pin advref or the voltage provided by the internal reference voltage which can be programmed in the analog control register (adc_acr). the selection of reference voltage source is defined by onref and forceref bits in the mode register (adc_mr). the adc supports the 8-bit or 10-bit resolution mode. the 8-bit resolution mode prevents using the 16-bit peripheral dma transfer into memory when only 8-bit resolution is required by the application. note that using this low resolution mode does not increase the conversion rate. conversion results are reported in a common register for all channels, as well as in a channel-dedicated register. the 11-bit and 12-bit resolution modes are obtained by averaging multiple samples to decrease quantization noise. for 11-bit mode, four samples are used, which gives an effective sample rate of 1/4 of the actual sample frequency. for 12-bit mode, 16 samples are used, giving an effective sample rate of 1/16th of the actual sample frequency.this allows conversion speed to be traded for better accuracy. the last channel is internally connected to a temperature sensor. the processing of this channel can be fully configured for efficient downstream processing due to the slow frequency variation of the value carried on such a sensor. the seventh channel is reserved for measurement of vddbu voltage. the software trigger, the external trigger on rising edge of the adtrg pin or internal triggers from timer counter output(s) are configurable. the main comparison circuitry allows automatic detection of values below a threshold, higher than a threshold, in a given range or outside the range. thresholds and ranges are fully configurable. the adc also integrates a sleep mode and a conversion sequencer, and connects with a pdc channel. these features reduce both power consumption and processor intervention. finally, the user can configure adc timings, such as startup time and tracking time. note: please check adc available signals in the main block diagram figure 2-1 . 40.2 embedded characteristics ? 10-bit resolution with enhanced mode up to 12 bits. ? 500 khz conversion rate. ? digital averaging function provides enhanced resolution mode up to 12 bits. ? on-chip temperature sensor management. ? wide range of power supply operation. ? selectable external voltage reference or programmable internal reference. ? integrated multiplexer offering up to 8 independent analog inputs. ? individual enable and disable of each channel. ? hardware or software trigger. ? external trigger pin. ? timer counter outputs (corresponding tioa trigger). ? pdc support. ? possibility of adc timings configuration. ? two sleep modes and conversion sequencer. ? automatic wake-up on trigger and back to sleep mode after conversions of all enabled channels. ? possibility of customized channel sequence. ? standby mode for fast wakeup time response. ? power down capability. ? automatic window comparison of converted values. ? register write protection.
906 sam4cp [datasheet] 43051e?atpl?08/14 40.3 block diagram figure 40-1. analog-to-digital converter block diagram 40.4 signal description notes: 1. ad7 is not an actual pin; it is internally connected to a temperature sensor. 2. ad6 is not an actual pin; it is internally connected to vddbu. 3. ad2 is not bounded to an external pin. 40.5 product dependencies 40.5.1 power management the adc controller is not continuously clocked. the programmer must first enable the adc controller mck in the power management controller (pmc) before using the adc controller. however, if the application does not require adc operations, the adc controller clock can be stopped when no t needed and restarted when necessary. configuring the adc controller does not require the adc controller clock to be enabled. 40.5.2 interrupt sources the adc interrupt line is connected on one of the internal sources of the interrupt controller. using the adc interrupt requires the interrupt controller to be programmed first. adc interrupt adtrg advref gnd trigger selection control logic successive approximation register analog-to-digital converter timer counter channels user interface interrupt controller peripheral bridge apb pdc system bus a nalog inputs multiplexed with i/o lines pio ad- ad- ad- adc controller pmc mck adc cell chx internal voltage reference onref temp. sensor 1hz rtc forceref vddin vddbu 6 7 table 40-1. adc pin description pin name description advref external reference voltage ad0 - ad7 (1)(2)(3) analog input channels adtrg external trigger
907 sam4cp [datasheet] 43051e?atpl?08/14 40.5.3 analog inputs the analog input pins can be multiplexed with pio lines. in this case, the assignment of the adc input is automatically done as soon as the corresponding channel is enabled by writing the channel enable register (adc_cher). by default, after reset, the pio line is configured as a digital input with its pull-up enabled and the adc input is connected to the gnd. 40.5.4 temperature sensor the temperature sensor is internally connected to channel index 7 of the adc. the temperature sensor provides an output voltage v t that is proportional to the absolute temperature (ptat). to activate the temperature sensor, the tempon bit in th e temperature sensor mode register (adc_tempmr) must be set. after setting the bit, the startup time of the temperature sensor must be achieved prior to initiating any measurement. 40.5.5 i/o lines the pin adtrg may be shared with other peripheral functions through the pio controller. in this case, the pio controller should be set accordingly to assign the pin adtrg to the adc function. 40.5.6 timer triggers timer counters may or may not be used as hardware triggers depending on user requirements. thus, some or all of the timer counters may be unconnected. 40.5.7 conversion performances for performance and electrical characteristics of the adc, see the electrical characteristics. table 40-2. peripheral ids instance id adc 29 table 40-3. i/o lines instance signal i/o line peripheral adc adtrg pb23 a adc com4/ad1 pa4 x1 adc seg6/ad0 pa12 x1 adc seg31/ad3 pb13 x1 adc seg41/ad4 pb23 x1 adc seg49/ad5 pb31 x1
908 sam4cp [datasheet] 43051e?atpl?08/14 40.6 functional description 40.6.1 analog-to-digital conversion the adc uses the adc clock to perform conversions. converting a single analog value to a 10-bit digital data requires tracking clock cycles as defined in the field tracktim of the ?adc mode register? on page 920 . the adc clock frequency is selected in the prescal field of adc_mr. the adc clock range is between mck/2, if prescal is 0, and mck/512, if prescal is set to 255 (0xff). prescal must be programmed in order to provide an adc clock frequency according to the parameters given in the electrical characteristics section. figure 40-2. sequence of adc conversions 40.6.2 conversion reference the conversion is performed on a full range between 0v and the reference voltage. the reference voltage is defined by the external pin advref, or programmed us ing the internal reference voltage th at is configured in adc_acr. analog inputs between these voltages convert to values based on a linear conversion. 40.6.3 conversion resolution the adc supports 8-bit or 10-bit resolutions. the 8-bit selection is performed by setting the lowres bit in adc_mr. by default, after a reset, the resolution is the highest and the data field in the data registers is fully used. by setting the lowres bit, the adc switches to the lowest resolution and the conversion results can be read in the lowest significant bits of the data registers. the two highest bits of the data field in the corresponding channel data register (adc_cdr) and of the ldata field in the last converted data register (adc_lcdr) read 0. 40.6.4 conversion results when a conversion is completed, the resulting 10-bit digital value is stored in adc_cdrx of the current channel and in adc_lcdr. by setting the tag option in the extended m ode register (adc_emr), adc_lcdr presents the channel number associated with the last converted data in the chnb field. the eocx bit and drdy in the interrupt status register (adc_isr) are set. in the case of a connected pdc channel, drdy rising triggers a data request. in any case, both eoc and drdy can trigger an interrupt. reading one adc_cdr clears the corresponding eoc bit. reading adc_lcdr clears the drdy bit. adcclock lcdr adc_on adc_sel drdy adc_start ch0 ch1 ch0 ch2 ch1 start up time (and tracking of ch0) conversion of ch0 conversion of ch1 tracking of ch1 tracking of ch2 adc_eoc trigger event (hard or soft) analog cell ios
909 sam4cp [datasheet] 43051e?atpl?08/14 figure 40-3. eocx and drdy flag behavior if adc_cdr is not read before further incoming data is converted, the corresponding overrun error (ovrex) flag is set in the overrun status register (adc_over). likewise, new data converted when drdy is high sets the govre bit (general overrun error) in adc_isr. the ovrex flag is automatically cleared when adc_over is read, and govre flag is automatically cleared when adc_isr is read. figure 40-4. govre and ovrex flag behavior warning: if the corresponding channel is disabled during a conversion or if it is disabled and then reenabled during a conversion, its associated data and its corresponding eoc and ovre flags in adc_isr are unpredictable. drdy (adc_isr) eocx (adc_isr) chx (adc_chsr) write the adc_cr with start = 1 read the adc_cdrx write the adc_cr with start = 1 read the adc_lcdr eoc0 govre ch0 (adc_chsr) trigger event eoc1 ch1 (adc_chsr) ovre0 (adc_over) undefined data data a data b adc_lcdr undefined data data a adc_cdr0 undefined data data b adc_cdr1 data c data c conversion c conversion a drdy (adc_isr) read adc_cdr1 read adc_cdr0 conversion b read adc_over read adc_isr ovre1 (adc_over) (adc_isr) (adc_isr) (adc_isr)
910 sam4cp [datasheet] 43051e?atpl?08/14 40.6.5 conversion triggers conversions of the active analog channels are started with a software or hardware trigger. the software trigger is provided by writing the control register (adc_cr) with the start bit at 1. the hardware trigger can be one of the tioa outputs of th e timer counter channels or the external trigger input of the adc (adtrg). the hardware trigger is selected with the trgsel field in adc_mr. the selected hardware trigger is enabled with the trgen bit in adc_mr. the minimum time between two consecutive trigger events must be strictly greater than the duration time of the longest conversion sequence as configured in the mode register (adc_mr), the channel status register (adc_chsr) and the channel sequence 1 register (adc_seqr1). if a hardware trigger is selected, the start of a conversion is triggered after a delay which starts at each rising edge of the selected signal. due to asynchronous handling, the delay may vary in a range of 2 mck clock periods to 1 adc clock period. figure 40-5. hardware trigger delay if one of the tioa outputs is selected, the corresponding timer counter channel must be programmed in waveform mode. only one start command is necessary to initiate a conversion sequence on all the channels. the adc hardware logic automatically performs the conversions on the active channels, then waits for a new request. the channel enable (adc_cher) and channel disable (adc_chdr) registers permit the analog channels to be enabled or disabled independently. if the adc is used with a pdc, only the transfers of converted data from enabled channels are performed and the resulting data buffers should be interpreted accordingly. 40.6.6 sleep mode and conversion sequencer the adc sleep mode maximizes power saving by automatically deactivating the adc when it is not being used for conversions. sleep mode is selected by setting the sleep bit in adc_mr. the sleep mode is managed by a conversion sequencer, which automatically processes the conversions of all channels at lowest power consumption. this mode can be used when the minimum period of time between two successive trigger events is greater than the startup period of the adc (see the adc characteristics section). when a start conversion request occurs, the adc is automatically activated. as the analog cell requires a start-up time, the logic waits during this time and starts the conversion on the enabled channels. when all conversions are complete, the adc is deactivated until the next trigger. triggers occurring during the sequence are not taken into account. the conversion sequencer allows automatic processing with minimum processor intervention and optimized power consumption. conversion sequences can be performed periodically using a timer/counter output. by using the pdc, the periodic acquisition of several samples can be processed automatically without any intervention of the processor. the sequence can be customized by programming adc_seqr1 an d setting to 1 the useq bit of adc_mr. the user can choose a specific order of channels and can program up to 8 conversions by sequence. the user is totally free to create his own sequence, by writing channel numbers in adc_seqr1. not only can channel numbers be written in any sequence, they can be repeated several times. only enabled sequence bits are converted. if all adc channels (i.e. 8) are used on an application board, there is no restrictions in the use of the user sequence. however, if some adc channels are not enabled for conversion but rather used as pure digital inputs, the respective indexes of these channels cannot be used in the user sequence fields in adc_seqr1. for example, if channel 3 is trigger start delay
911 sam4cp [datasheet] 43051e?atpl?08/14 disabled (adc_csr[3] = 0), adc_seqr1 fields usch1 up to usch8 must not contain the value 3. thus the length of the user sequence may be limited by this behavior. as an example, if only four channels over 8 (ch0 up to ch3) are selected for adc conversions, the user sequence length cannot exceed four channels. each trigger event may launch up to four successive conversions of any combination of channels 0 up to 3 but no more (i.e., in this case the sequence ch0, ch0, ch1, ch1, ch1 is impossible). a sequence that repeats the same channel several times requ ires more enabled channels than channels actually used for conversion. for example, the sequence ch0, ch0, ch1, ch1 requires four enabled channels (four free channels on application boards) whereas only ch0, ch1 are really converted. 40.6.7 comparison window the adc controller features automatic comparison functions. it compares converted values to a low threshold, a high threshold or both, depending on the cmpmode function chosen in the extended mode register (adc_emr). the comparison can be done on all channels or only on the channel specified in cmpsel field of adc_emr. to compare all channels, the cmpall bit of adc_emr should be set. moreover, a filtering option can be set by writing the number of consecutive comparison errors needed to raise the flag. this number can be written and read in the cmpfilter field of adc_emr. the flag can be read on the compe bit of adc_isr and can trigger an interrupt. the high threshold and the low threshold can be read/write in the compare window register (adc_cwr). if the comparison window is to be used with the lowres bit in adc_mr set to 1, the thresholds do not need to be adjusted as adjustment will be done internally. whether or not the lowres bit is set, thresholds must always be configured in consideration of the maximum adc resolution. 40.6.8 adc timings each adc has its own minimal startup time that is programmed through the field startup in adc_mr. a minimal tracking time is necessary for the adc to guarantee the best converted final value between two channel selections. this time has to be programmed through the tracktim field in adc_mr. warning: no input buffer amplifier to isolate the source is included in the adc. this must be taken into consideration to program a precise value in the tracktim field. see the adc characteristics section. 40.6.9 temperature sensor the temperature sensor is internally connected to channel index 7. for temperature measurement, the tempon bit must be written to 1 in adc_tempmr. the temperature measurement can be made in different ways through the adc controller. the different methods of measurement depend on the configuration bits trgen in adc_mr and ch7 in adc_chsr. the temperature measurement can be triggered like the other channels by enabling its associated conversion channel index 7, writing to 1 the bit ch7 of adc_cher. the manual start can only be performed if trgen bit in adc_mr is disabled. when the start bit in adc_cr is written to 1, the temperature sensor channel conversion will be scheduled together with the other enabled channels (if any). the result of the conversion is placed in the adc_cdr7 register and the associated flag eoc7 is set in adc_isr. if the trgen bit is set in adc_mr, the channel of the temperature sensor is periodically converted together with other enabled channels and the result is pl aced on adc_lcdr and adc_cdr7. thus the temperature conversion result is part of the peripheral dma controller buffer. the temperature channel can be enabled/disabled at anytime but this may not be optimal for downstream processing.
912 sam4cp [datasheet] 43051e?atpl?08/14 figure 40-6. non-optimized temperature conversion the temperature factor has a slow variation rate and is potentially different from other conversion channels. as a result, the adc controller triggers the measurement differently when tempon is set in adc_te mpmr but ch7 is not set in the adc_chsr. under these conditions, the measurement is triggered every second by means of an internal trigger generated by rtc, always enabled and totally independent of the internal/external triggers. the rtc event will be taken into account on the next internal/external trigger event as described in figure 40-7, "optimized temperature conversion combined with classical conversions" . the internal/external trigger is selected through the trgsel field of adc_mr. in this mode of operation, the temperature sensor is only powered for a period of time covering the startup time and conversion time (refer to figure 40-8, "temperature conversion only" for more details). every second, a conversion is scheduled for channel 7 but the result of the conversion is only uploaded in adc_cdr7 and not in adc_lcdr. therefore there is no change in the structure of the peripheral dma controller buffer due to the conversion of the temperature channel; only the enabled channels are kept in the bu ffer. the end of conversion of the temperature channel is reported by means of eoc7 flag in adc_isr. base address (ba) ba + 0x02 adc_cdr[temp] 0 adc_cdr[0] 0 adc_cdr[0] 0 ba + 0x04 adc_cdr[0] 0 adc_cdr[temp] 0 adc_cdr[temp] 0 ba + 0x06 ba + 0x08 ba + 0x0a assu m ing adc_chsr[0] = 1 and adc_chsr[temp] = 1 where temp is the inde x of the te m perature sensor channel trig.event1 dma buffer structure trig.event2 dma transfer trig.event3 adc_sel c t c t t c t c c: classic adc conversion sequence - t: te m perature sensor channel c t adc_chsr[temp]= 1 and adc_mr.trgen=1 adc_cdr[temp] t1 t2 t0 adc_cdr[0] c0 c1 c2 c3 c4 c5 t3 t4 t5 adc_lcdr c0 c1 c2 c3 c4 t1 t2 t0 t3 t4 t5 internal/e x ternal trigger event (trgsel defined)
913 sam4cp [datasheet] 43051e?atpl?08/14 figure 40-7. optimized temperature conversion combined with classical conversions if tempon = 1, trgen is disabled and none of the channels is enabled in the adc_chsr (adc_chsr=0), then only channel 7 is converted at a rate of one conversion per second (see figure 40-8, "temperature conversion only" ). this mode of operation, when combined with the sleep mode operation of the adc controller, provides a low-power mode for temperature measurement. this assumes there is no other adc conversion to schedule at a high sampling rate or simply no other channel to convert. figure 40-8. temperature conversion only base address (ba) ba + 0x02 adc_cdr[0] 0 ba + 0x04 adc_cdr[0] 0 assu m ing adc_chsr[0] = 1 trig.event1 dma buffer structure trig.event2 dma transfer trig.event3 adc_sel c t c c t c c: classic adc conversion sequence - t: te m perature sensor channel c adc_chsr[temp]= 0 and adc_mr.trgen=1 tempon=1 adc_cdr[0] 0 internal rtc trigger event adc_cdr[temp] t1 t2 t0 adc_cdr[0] & adc_lcdr c0 c1 c2 c3 c4 c5 1 s internal/e x ternal trigger event (trgsel defined) adc_sel adc_chsr= 0 and adc_mr.trgen=0 internal rtc trigger event 1 s auto m atic on te m p. sensor t t 30 us on off adc_cdr[temp] t1 t2 t0 tempon=1
914 sam4cp [datasheet] 43051e?atpl?08/14 moreover, it is possible to raise a flag only if there is a predefined change in the temperature. the user can define a range of temperature or a threshold in the temperature compare window register (adc_tempcwr), and the mode of comparison that can be programmed into ad c_tempmr by means of the tempcm pmod field. these values define the way the tempchg flag is raised in adc_isr. the tempchg flag can be used to generate a temperature-dependent interrupt instead of the end-of-conversion interrupt. in particular, the interrupt is generated only if the temperature sensor, as measured by the adc, reports a temperature value below, above, inside or outside programmable thresholds (see adc_tempmr). in any case, if tempon is set, the temperature can be read at anytime in adc_cdr7 without any specific software intervention. 40.6.10 vddbu measurement the seventh adc channel (ch6) of the adc controller is reserved for measurement of the vddbu power supply pin. for this channel, setting up, starting conversion, and other tasks must be performed the same way as for all other channels. vddbu is measured without any attenuation. this means that for vddbu greater than the voltage reference applied to the adc, the digital output clamps to the maximum value. 40.6.11 enhanced resolution mode and digital averaging function the enhanced resolution mode is enabled if lowres is cleared in adc_mr, and the osr field is set to 1, 2 in adc_emr. the enhancement is based on a digital averaging function. freerun must be set to 0 when digital averaging is used (osr differs from 0 in adc_emr). there is no averaging on the last index channel if the measure is triggered by an rtc event (see section 40.6.9 ?temperature sensor? ). in enhanced resolution mode, the adc controller trades conversion speed for quantization noise by averaging multiple samples, thus providing a digital low-pass filter function. if 1-bit enhancement resolution is selected (osr = 1 in adc_emr), the adc effective sample rate is the maximum adc sample rate divided by 4; therefore, the oversampling ratio is 4. when the 2-bit enhancement resolution is selected (osr = 2 in adc_emr), the adc effective sample rate is the maximum adc sample rate divided by 16 (oversampling ratio is 16). the selected oversampling ratio applies to all enabled channels except for the temperature sensor channel when triggered by an rtc event. the average result is valid into the adc_cdrx register (x corresponding to the index of the channel) only if eocn flag is set in adc_isr and ovren flag is cleared in adc_over. the average result for all channels is valid in adc_lcdr only if drdy is set and govre is cleared in adc_isr. note that adc_cdrx are not buffered. therefore, when an averaging sequence is ongoing, the value in these registers changes after each averaging sample. on the other hand, overrun flags in adc_over rise as soon as the first sample of an averaging sequence is received and thus the previous averaged value is not read (even if the new averaged value is not ready). in consequence, when an overrun flag rises in adc_over, th e previous unread data is lost but the data has not been overwritten by the new averaged value, as the averaging sequence concerning this channel may still be on-going. 40.6.11.1 averaging function versus trigger events the samples can be defined in different ways for the averaging function depending on the configuration of the aste bit in adc_emr and the useq bit in adc_mr. when useq is cleared, there are two ways to generate the averaging through the trigger event. if aste bit is cleared in adc_emr, every trigger event generates one sample for each enabled channel as described in figure 40-9, "digital averaging function waveforms over multiple trigger events" . therefore, four trigger events are requested to get the result of averaging if osr = 1.
915 sam4cp [datasheet] 43051e?atpl?08/14 figure 40-9. digital averaging function waveforms over multiple trigger events if aste = 1 in the adc_emr and useq = 0 in adc_mr, then the sequence to be converted, defined in adc_chsr, is automatically repeated n times (where n corresponds to the oversampling rati o defined in the osr field in adc_emr. as a result, only one trigger is required to obtain the result of the averaging function as described in figure 40-10, "digital averaging function waveforms on a single trigger event" . figure 40-10. digital averaging function waveforms on a single trigger event internal/e x ternal trigger event adc_sel 0 1 adc_emr.osr=1 aste=0, adc_chsr[1:0]= 0 x 3 and adc_mr.useq=0 adc_cdr[1] adc_cdr[0] ch0_0 adc_lcdr 0i1 0 1 0 1 0 1 0 1 0i2 0i3 ch0_1 0i1 ch1_0 1i1 1i2 1i3 ch1_1 1i1 eoc[0] read adc_cdr[1] ch1_1 ch0_1 eoc[1] read adc_lcdr drdy note: 0i1,0i2,0i3, 1i1, 1i2, 1i3 are inter m ediate results and ch0/1_0/1 are final result of average function. read adc_cdr[0] read adc_cdr[1] ovr[0] ch1_0 read adc_lcdr internal/e x ternal trigger event adc_sel 0 adc_emr.osr=1, aste=1 , adc_chsr[1:0]= 0 x 3 and adc_mr.useq=0 adc_cdr[1] adc_cdr[0] ch0_0 adc_lcdr 0i1 0 0i2 0i3 ch0_1 eoc[0] read adc_cdr[0] read adc_cdr[1] ch1_1 ch0_1 eoc[1] read adc_lcdr drdy 0 1 11 0 0 ch1_0 1i1 1i2 1i3 ch1_1 note: 0i1,0i2,0i3, 1i1, 1i2, 1i3 are inter m ediate results and ch0/1_0/1 are final result of average function. 01 1 1
916 sam4cp [datasheet] 43051e?atpl?08/14 when useq is set, the user can define the channel sequence to be converted by configuring adc_seqrx and adc_cher so that channels are not interleaved during the averaging period. under these conditions, a sample is defined for each end of conversion as shown in figure 40-11, "digital averaging f unction waveforms on single trigger event, non-interleaved" . therefore, if the same channel is configured to be converted four times consecutively, and osr = 1 in adc_emr, the averaging result will be placed in the corresponding channel data register (adc_cdrx) and last converted data register (adc_lcdr) for each trigger event. in such a case, the adc effective sample rate remains the maximum adc sample rate divided by 4 or 16, depending on osr. when useq = 1, aste = 1 and osr is different from 0, it is important to note that the user sequence must follow a specific pattern. the user sequence must be programmed so that it generates a stream of conversion, where a given channel is successively converted with an integer multiple depending on the value of osr. up to four channels can be converted in this specific mode. when osr = 1, each channel to convert must be repeated four times consecutively in the sequence, so the first four single bits enabled in adc_chsr must have the associated channel index programmed to the same value in adc_seq1/2. therefore, for osr = 1, a maximum of four channels can be converted (the user sequence allows a maximum of 16 conversions for each trigger event). when osr = 2, a channel to convert must be repeated 16 times consecutively in the sequence, so all fields must be enabled in the adc_chsr register, and their associated channel index programmed to the same value in adc_seq1/2. therefore, for osr = 2, only one channel can be converted (the user sequence allows a maximum of 16 conversions for each trigger event). osr = 3 and osr = 4 are prohibited when useq = 1 and aste = 1. figure 40-11. digital averaging function waveforms on single trigger event, non-interleaved internal/e x ternal trigger event adc_sel 0 adc_emr.osr=1 , aste=1, adc_chsr[7:0]= 0 x ff and adc_mr.useq=1 adc_cdr[1] adc_cdr[0] ch0_0 adc_lcdr 0i1 00 0i2 0i3 ch0_1 eoc[0] read adc_cdr[0] read adc_cdr[1] ch1_1 ch0_1 eoc[1] read adc_lcdr drdy 0 1 111 0 000 ch1_0 1i1 1i2 1i3 ch1_1 note: 0i1,0i2,0i3, 1i1, 1i2, 1i3 are inter m ediate results and ch0/1_0/1 are final result of average function. adc_seq1r = 0 x 1111_0000
917 sam4cp [datasheet] 43051e?atpl?08/14 40.6.11.2 oversampling digital output range when an oversampling is performed, the maximum value that can be read on adc_cdrx or adc_lcdr is not the full scale value, even if the maximum voltage is supplied on the analog input. this is due to the digital averaging algorithm. for example, when osr = 1, four samples are accumulated and the result is then right-shifted by 1 (divided by 2). the maximum output value carried on adc_cdrx or adc_lcdr depends on the osr value configured in adc_emr. 40.6.12 buffer structure the pdc read channel is triggered each time a new data is stored in adc_lcdr. the same structure of data is repeatedly stored in adc_lcdr each time a trigger event occurs. depending on user mode of operation (adc_mr, adc_chsr, adc_seqr1) the structure differs. each data read to the pdc buffer, carried on a half-word (16-bit), consists of last converted data right-aligned. when tag is set in adc_emr, the four most significant bits carry the channel number, thus simplifying post-processing in the pdc buffer or improved checking of the pdc buffer integrity. 40.7 register write protection to prevent any single software error from corrupting adc behavior, certain registers in the address space can be write-protected by setting the wpen bit in the ?adc write protection mode register? (adc_wpmr). if a write access to a write-protected register is detected, the wpvs flag in the ?adc write protection status register? (adc_wpsr) is set and the field wpvsrc indicates the register in which the write access has been attempted. the wpvs bit is automatically cleared after reading the adc_wpsr. the following registers can be write-protected: ? ?adc mode register? on page 920 ? ?adc channel sequence 1 register? on page 922 ? ?adc channel enable register? on page 923 ? ?adc channel disable register? on page 924 ? ?adc temperature sensor mode register? on page 931 ? ?adc temperature compare window register? on page 932 ? ?adc extended mode register? on page 934 ? ?adc compare window register? on page 936 ? ?adc analog control register? on page 938 table 40-4. oversampling digital output range values resolution samples shift full scale value maximum value 8-bit 1 0 255 255 10-bit 1 0 1023 1023 11-bit 4 1 2047 2046 12-bit 16 2 4095 4092
918 sam4cp [datasheet] 43051e?atpl?08/14 40.8 analog-to-digital converter (adc) user interface note: if an offset is not listed in the table it must be considered as ?reserved?. table 40-5. register mapping offset register name access reset 0x00 control register adc_cr write-only ? 0x04 mode register adc_mr read/write 0x00000000 0x08 channel sequence register 1 adc_seqr1 read/write 0x00000000 0x0c reserved ? ? ? 0x10 channel enable register adc_cher write-only ? 0x14 channel disable register adc_chdr write-only ? 0x18 channel status register adc_chsr read-only 0x00000000 0x1c reserved ? ? ? 0x20 last converted data register adc_lcdr read-only 0x00000000 0x24 interrupt enable register adc_ier write-only ? 0x28 interrupt disable register adc_idr write-only ? 0x2c interrupt mask register adc_imr read-only 0x00000000 0x30 interrupt status register adc_isr read-only 0x00000000 0x34 temperature sensor mode register adc_tempmr read/write 0x00000000 0x38 temperature compare window register adc_tempcwr read/write 0x00000000 0x3c overrun status register adc_over read-only 0x00000000 0x40 extended mode register adc_emr read/write 0x00000000 0x44 compare window register adc_cwr read/write 0x00000000 0x50 channel data register 0 adc_cdr0 read-only 0x00000000 0x54 channel data register 1 adc_cdr1 read-only 0x00000000 ... ... ... ... ... 0x6c channel data register 7 adc_cdr7 read-only 0x00000000 0x70 - 0x90 reserved ? ? ? 0x94 analog control register adc_acr read/write 0x00000000 0x98 - 0xac reserved ? ? ? 0xc4 - 0xe0 reserved ? ? ? 0xe4 write protection mode register adc_wpmr read/write 0x00000000 0xe8 write protection status register adc_wpsr read-only 0x00000000 0xec - 0xf8 reserved ? ? ? 0xfc reserved ? ? ? 0x100 - 0x124 reserved for pdc registers ? ? ?
919 sam4cp [datasheet] 43051e?atpl?08/14 40.8.1 adc control register name: adc_cr address: 0x40038000 access: write-only ? swrst: software reset 0 = no effect. 1 = resets the adc simulating a hardware reset. ? start: start conversion 0 = no effect. 1 = begins analog-to-digital conversion. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? ? ? ? ? start swrst
920 sam4cp [datasheet] 43051e?atpl?08/14 40.8.2 adc mode register name: adc_mr address: 0x40038004 access: read/write this register can only be written if the wpen bit is cleared in ?adc write protection mode register? on page 939 . ? trgen: trigger enable ? trgsel: trigger selection ? lowres: resolution 31 30 29 28 27 26 25 24 useq ? ? ? tracktim 23 22 21 20 19 18 17 16 ???? startup 15 14 13 12 11 10 9 8 prescal 76543210 freerun ? sleep lowres trgsel trgen value name description 0 dis hardware triggers are disabled. starting a conversion is only possible by software 1 en hardware trigger selected by trgsel field is enabled value name description 0 adc_trig0 external trigger adtrg 1 adc_trig1 timer counter channel 0 output 2 adc_trig2 timer counter channel 1 output 3 adc_trig3 timer counter channel 2 output 4 adc_trig4 timer counter channel 3 output 5 adc_trig5 timer counter channel 4 output 6 adc_trig6 timer counter channel 5 output 7 ? reserved value name description 0 bits_10 10-bit resolution. for higher resolution by averaging, refer to section 40.8.15 ?adc extended mode register? 1 bits_8 8-bit resolution
921 sam4cp [datasheet] 43051e?atpl?08/14 ? sleep: sleep mode ? freerun: free run mode note: freerun must be set to 0 when digital averaging is used (osr differs from 0 in adc_emr register). ? prescal: prescaler rate selection adcclock = mck / ((prescal+1) * 2). ? startup: start up time ? tracktim: tracking time tracking time = (tracktim + 1) * adcclock periods. ? useq: use sequence enable value name description 0 normal normal mode: the adc core and reference voltage circuitry are kept on between conversions 1 sleep sleep mode: the adc core and reference voltage circuitry are off between conversions value name description 0 off normal mode 1 on free run mode: never wait for any trigger value name description 0 sut0 0 periods of adcclock 1 sut8 8 periods of adcclock 2 sut16 16 periods of adcclock 3 sut24 24 periods of adcclock 4 sut64 64 periods of adcclock 5 sut80 80 periods of adcclock 6 sut96 96 periods of adcclock 7 sut112 112 periods of adcclock 8 sut512 512 periods of adcclock 9 sut576 576 periods of adcclock 10 sut640 640 periods of adcclock 11 sut704 704 periods of adcclock 12 sut768 768 periods of adcclock 13 sut832 832 periods of adcclock 14 sut896 896 periods of adcclock 15 sut960 960 periods of adcclock value name description 0 num_order normal mode: the controller converts channels in a simple numeric order depending only on the channel index 1 reg_order user sequence mode: the sequence respects what is defined in adc_seqr1 and can be used to convert the same channel several times
922 sam4cp [datasheet] 43051e?atpl?08/14 40.8.3 adc channel sequence 1 register name: adc_seqr1 address: 0x40038008 access: read/write this register can only be written if the wpen bit is cleared in ?adc write protection mode register? . ? uschx: user sequence number x the sequence number x (uschx) can be programmed by the channel number chy where y is the value written in this field. the allowed range is 0 up to 7. so it is only possible to use the sequencer from ch0 to ch7 . this register activates only if adc_mr(useq) field is set to 1. any uschx field is taken into account only if adc_chsr(chx) register field reads logical 1; else any value written in uschx does not add the corresponding channel in the conversion sequence. configuring the same value in different fields leads to multiple samples of the same channel during the conversion sequence. th is can be done consecutively, or not, depending on user needs. 31 30 29 28 27 26 25 24 usch8 usch7 23 22 21 20 19 18 17 16 usch6 usch5 15 14 13 12 11 10 9 8 usch4 usch3 76543210 usch2 usch1
923 sam4cp [datasheet] 43051e?atpl?08/14 40.8.4 adc channel enable register name: adc_cher address: 0x40038010 access: write-only this register can only be written if the wpen bit is cleared in ?adc write protection mode register? . ? chx: channel x enable 0 = no effect. 1 = enables the corresponding channel. note: if useq = 1 in the adc_mr, chx corresponds to the xth channel of the sequence described in adc_seqr1. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ch7 ch6 ch5 ch4 ch3 ch2 ch1 ch0
924 sam4cp [datasheet] 43051e?atpl?08/14 40.8.5 adc channel disable register name: adc_chdr address: 0x40038014 access: write-only this register can only be written if the wpen bit is cleared in ?adc write protection mode register? . ? chx: channel x disable 0 = no effect. 1 = disables the corresponding channel. warning: if the corresponding channel is disabled during a conversion or if it is disabled then reenabled during a conversion, its associated data and its corresponding eoc and ovre flags in adc_isr are unpredictable. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ch7 ch6 ch5 ch4 ch3 ch2 ch1 ch0
925 sam4cp [datasheet] 43051e?atpl?08/14 40.8.6 adc channel status register name: adc_chsr address: 0x40038018 access: read-only ? chx: channel x status 0 = the corresponding channel is disabled. 1 = the corresponding channel is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ch7 ch6 ch5 ch4 ch3 ch2 ch1 ch0
926 sam4cp [datasheet] 43051e?atpl?08/14 40.8.7 adc last converted data register name: adc_lcdr address: 0x40038020 access: read-only ? ldata: last data converted the analog-to-digital conversion data is placed into this register at the end of a conversion and remains until a new conversio n is completed. ? chnb: channel number indicates the last converted channel when the tag option is set to 1 in adc_emr. if the tag option is not set, chnb = 0. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 chnb ldata 76543210 ldata
927 sam4cp [datasheet] 43051e?atpl?08/14 40.8.8 adc interrupt enable register name: adc_ier address: 0x40038024 access: write-only the following configuration values are valid for all listed bit names of this register: 0 = no effect. 1 = enables the corresponding interrupt. ? eocx: end of conversion interrupt enable x ? tempchg: temperature change interrupt enable ? drdy: data ready interrupt enable ? govre: general overrun error interrupt enable ? compe: comparison event interrupt enable ? endrx: end of receive buffer interrupt enable ? rxbuff: receive buffer full interrupt enable 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ? ? ? ? tempchg ? ? ? 15 14 13 12 11 10 9 8 ???????? 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
928 sam4cp [datasheet] 43051e?atpl?08/14 40.8.9 adc interrupt disable register name: adc_idr address: 0x40038028 access: write-only the following configuration values are valid for all listed bit names of this register: 0 = no effect. 1 = disables the corresponding interrupt. ? eocx: end of conversion interrupt disable x ? tempchg: temperature change interrupt disable ? drdy: data ready interrupt disable ? govre: general overrun error interrupt disable ? compe: comparison event interrupt disable ? endrx: end of receive buffer interrupt disable ? rxbuff: receive buffer full interrupt disable 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ? ? ? ? tempchg ? ? ? 15 14 13 12 11 10 9 8 ???????? 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
929 sam4cp [datasheet] 43051e?atpl?08/14 40.8.10 adc interrupt mask register name: adc_imr address: 0x4003802c access: read-only the following configuration values are valid for all listed bit names of this register: 0 = the corresponding interrupt is disabled. 1 = the corresponding interrupt is enabled. ? eocx: end of conversion interrupt mask x ? tempchg: temperature change interrupt mask ? drdy: data ready interrupt mask ? govre: general overrun error interrupt mask ? compe: comparison event interrupt mask ? endrx: end of receive buffer interrupt mask ? rxbuff: receive buffer full interrupt mask 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ? ? ? ? tempchg ? ? ? 15 14 13 12 11 10 9 8 ???????? 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
930 sam4cp [datasheet] 43051e?atpl?08/14 40.8.11 adc interrupt status register name: adc_isr address: 0x40038030 access: read-only ? eocx: end of conversion x 0 = the corresponding analog channel is disabled, or the conversion is not finished. this flag is cleared when reading the corresponding adc_cdrx registers. 1 = the corresponding analog channel is enabled and conversion is complete. ? tempchg: temperature change 0 = there is no comparison match (defined in the adc_tempcwr) since the last read of adc_isr. 1 = the temperature value reported on adc_cdr7 has changed since the last read of adc_isr, according to what is defined in adc_tempmr and adc_tempcwr. ? drdy: data ready 0 = no data has been converted since the last read of adc_lcdr. 1 = at least one data has been converted and is available in adc_lcdr. ? govre: general overrun error 0 = no general overrun error occurred since the last read of adc_isr. 1 = at least one general overrun error has occurred since the last read of adc_isr. ? compe: comparison error 0 = no comparison error since the last read of adc_isr. 1 = at least one comparison error (defined in adc_emr and adc_cwr) has occurred since the last read of adc_isr. ? endrx: end of rx buffer 0 = the receive counter register has not reached 0 since the last write in adc_rcr or adc_rncr. 1 = the receive counter register has reached 0 since the last write in adc_rcr or adc_rncr. ? rxbuff: rx buffer full 0 = adc_rcr or adc_rncr have a value other than 0. 1 = both adc_rcr and adc_rncr have a value of 0. 31 30 29 28 27 26 25 24 ? ? ? rxbuff endrx compe govre drdy 23 22 21 20 19 18 17 16 ? ? ? ? tempchg ? ? ? 15 14 13 12 11 10 9 8 ???????? 76543210 eoc7 eoc6 eoc5 eoc4 eoc3 eoc2 eoc1 eoc0
931 sam4cp [datasheet] 43051e?atpl?08/14 40.8.12 adc temperature sensor mode register name: adc_tempmr address: 0x40038034 access: read/write this register can only be written if the wpen bit is cleared in ?adc write protection mode register? . ? tempon: temperature sensor on 0 = the temperature sensor is not enabled. 1 = the temperature sensor is enabled and the measurements are triggered. ? tempcmpmod: temperature comparison mode 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ? ? tempcmpmod ? ? ? tempon value name description 0 low generates an event when the converted data is lower than the low threshold of the window 1 high generates an event when the converted data is higher than the high threshold of the window 2 in generates an event when the converted data is in the comparison window 3 out generates an event when the converted data is out of the comparison window
932 sam4cp [datasheet] 43051e?atpl?08/14 40.8.13 adc temperature compare window register name: adc_tempcwr address: 0x40038038 access: read/write this register can only be written if the wpen bit is cleared in the ?adc write protection mode register? . ? tlowthres: temperature low threshold low threshold associated to compare settings of adc_tempmr. ? thighthres: temperature high threshold high threshold associated to compare settings of adc_tempmr. 31 30 29 28 27 26 25 24 ? ? ? ? thighthres 23 22 21 20 19 18 17 16 thighthres 15 14 13 12 11 10 9 8 ? ? ? ? tlowthres 76543210 tlowthres
933 sam4cp [datasheet] 43051e?atpl?08/14 40.8.14 adc overrun status register name: adc_over address: 0x4003803c access: read-only ? ovrex: overrun error x 0 = no overrun error on the corresponding channel since the last read of adc_over. 1 = there has been an overrun error on the corresponding channel since the last read of adc_over. note: an overrun error does not always mean that the unread data has been replaced by a new valid data. refer to section 40.6.11 ?enhanced resolution mode and digital averaging function? for details. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ovre7 ovre6 ovre5 ovre4 ovre3 ovre2 ovre1 ovre0
934 sam4cp [datasheet] 43051e?atpl?08/14 40.8.15 adc extended mode register name: adc_emr address: 0x40038040 access: read/write this register can only be written if the wpen bit is cleared in ?adc write protection mode register? . ? cmpmode: comparison mode ? cmpsel: comparison selected channel if cmpall = 0: cmpsel indicates which channel has to be compared. if cmpall = 1: no effect. ? cmpall: compare all channels 0 = only channel indicated in cmpsel field is compared. 1 = all channels are compared. ? cmpfilter: compare event filtering number of consecutive compare events necessary to raise the flag = cmpfilter+1. when programmed to 0, the flag rises as soon as an event occurs. ? osr: over sampling rate this field is active if lowres is cleared in ?adc mode register? on page 920 . note: freerun (see adc_mr register) must be set to 0 when digital averaging is used. 31 30 29 28 27 26 25 24 ???????tag 23 22 21 20 19 18 17 16 ? ? ? aste ? ? osr 15 14 13 12 11 10 9 8 ? ? cmpfilter ? ? cmpall ? 76543210 cmpsel ? ? cmpmode value name description 0 low generates an event when the converted data is lower than the low threshold of the window 1 high generates an event when the converted data is higher than the high threshold of the window 2 in generates an event when the converted data is in the comparison window 3 out generates an event when the converted data is out of the comparison window value name description 0 no_average no averaging. adc sample rate is maximum 1 osr4 1-bit enhanced resolution by interpolation. adc sample rate divided by 4 2 osr16 2-bit enhanced resolution by interpolation. adc sample rate divided by 16
935 sam4cp [datasheet] 43051e?atpl?08/14 ? aste: averaging on single trigger event ? tag: tag of the adc_ldcr register 0 = sets chnb to zero in adc_ldcr. 1 = appends the channel number to the conversion result in adc_ldcr. value name description 0 multi_trig_average the average requests several trigger events 1 single_trig_average the average requests only one trigger event
936 sam4cp [datasheet] 43051e?atpl?08/14 40.8.16 adc compare window register name: adc_cwr address: 0x40038044 access: read/write this register can only be written if the wpen bit is cleared in ?adc write protection mode register? . ? lowthres: low threshold low threshold associated to compare settings of adc_emr. if lowres is set in adc_mr, only the 10 lsb of lowthres must be programmed. the 2 lsb will be automatically discarded to match the value carried on adc_cdr (8-bit). ? highthres: high threshold high threshold associated to compare settings of adc_emr. if lowres is set in adc_mr, only the 10 lsb of highthres must be programmed. the 2 lsb will be automatically discarded to match the value carried on adc_cdr (8-bit). 31 30 29 28 27 26 25 24 ? ? ? ? highthres 23 22 21 20 19 18 17 16 highthres 15 14 13 12 11 10 9 8 ? ? ? ? lowthres 76543210 lowthres
937 sam4cp [datasheet] 43051e?atpl?08/14 40.8.17 adc channel data register name: adc_cdrx [x=0..7] address: 0x40038050, 0x40038054, 0x40038058, 0x4003805c, 0x40038060, 0x40038064, 0x40038068, 0x4003806c access: read-only ? data: converted data the analog-to-digital conversion data is placed into this register at the end of a conversion and remains until a new conversio n is completed. the channel data register (cdr) is only loaded if the corresponding analog channel is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???? data 76543210 data
938 sam4cp [datasheet] 43051e?atpl?08/14 40.8.18 adc analog control register name: adc_acr address: 0x40038094 access: read/write this register can only be written if the wpen bit is cleared in ?adc write protection mode register? . ? irvce: internal reference voltage change enable 0 (stuck_at_default) = the internal reference voltage is stuck at the default value (see the electrical characteristics for further details). 1 (selection) = the internal reference voltage is defined by field irvs. ? irvs: internal reference voltage selection see the electrical characteristics for further details. ? forceref: force internal reference voltage 0 = the internal voltage reference is defined. 1 = the internal voltage reference is forced to vddio (onref must be set to 0). ? onref: internal voltage reference on 0 = the external pin advref defines the voltage reference. 1 = the internal voltage reference is selected (forceref must be set to 0). 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ? ? ? onref forceref ? ? ? 15 14 13 12 11 10 9 8 ???????? 76543210 ? irvs irvce ? ?
939 sam4cp [datasheet] 43051e?atpl?08/14 40.8.19 adc write protection mode register name: adc_wpmr address: 0x400380e4 access: read/write for more information on write protection registers, refer to section 40.7 ?register write protection? . ? wpen: write protect enable 0 = disables the write protection if wpkey corresponds to 0x414443 (?adc? in ascii). 1 = enables the write protection if wpkey corresponds to 0x414443 (?adc? in ascii). see section 40.7 ?register write protection? for the list of registers that can be protected. ? wpkey: write protect key 31 30 29 28 27 26 25 24 wpkey 23 22 21 20 19 18 17 16 wpkey 15 14 13 12 11 10 9 8 wpkey 76543210 ??????? wpen value name description 0x414443 passwd writing any other value in this field aborts the write operation of the wpen bit. always reads as 0.
940 sam4cp [datasheet] 43051e?atpl?08/14 40.8.20 adc write protection status register name: adc_wpsr address: 0x400380e8 access: read-only for more information on write protection registers, refer to section 40.7 ?register write protection? . ? wpvs: write protection violation status 0 = no write protection violation has occurred since the last read of the adc_wpsr register. 1 = a write protection violation has occurred since the last read of the adc_wpsr register. if this violation is an unauthorize d attempt to write a protected register, the associated violation is reported into field wpvsrc. ? wpvsrc: write protection violation source when wpvs = 1, wpvsrc indicates the register address offset at which a write access has been attempted. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 wpvsrc 15 14 13 12 11 10 9 8 wpvsrc 76543210 ??????? wpvs
941 sam4cp [datasheet] 43051e?atpl?08/14 41. advanced encryption standard (aes) 41.1 description the advanced encryption standard (aes) is compliant with the american fips (federal information processing standard) publication 197 specification. the aes supports all five confidentiality modes of operation for symmetrical key block cipher algorithms (ecb, cbc, ofb, cfb and ctr), as specified in the nist special publication 800-38a recommendation, as well as galois/counter mode (gcm) as specified in the nist special publication 800-38d recommendation . it is compatible with all these modes via peripheral dma controller channels, minimizing processor intervention for large buffer transfers. the 128-bit/192-bit/256-bit key is stored in four/six/eight 32-bit write-only aes key word registers (aes_keywrx). the 128-bit input data and initialization vector (for some modes) are each stored in four 32-bit write-only aes input data registers (aes_idatarx) and aes initialization vector registers (aes_ivrx). as soon as the initialization vector, the input data and the key are configured, the encryption/decryption process may be started. then the encrypted/decrypted data are ready to be read out on the four 32-bit aes output data registers (aes_odatarx) or through the pdc channels. 41.2 embedded characteristics ? compliant with fips publication 197, advanced encryption standard (aes). ? 128-bit/192-bit/256-bit cryptographic key. ? 12/14/16 clock cycles encryption/decryption processing time with a 128-bit/192-bit/256-bit cryptographic key. ? double input buffer optimizes runtime. ? support of the modes of operation specified in the nist special publication 800-38a and nist special publication 800-38d: ? electronic code book (ecb). ? cipher block chaining (cbc) including cbc-mac. ? cipher feedback (cfb). ? output feedback (ofb). ? counter (ctr). ? galois/counter mode (gcm). ? 8-, 16-, 32-, 64- and 128-bit data sizes possible in cfb mode. ? last output data mode allows optimized message authentication code (mac) generation. ? connection to pdc channel capabilities optimizes data transfers for all operating modes. ? one channel for the receiver, one channel for the transmitter. ? next buffer support. 41.3 product dependencies 41.3.1 power management the aes may be clocked through the power management controller (pmc), so the programmer must first to configure the pmc to enable the aes clock. 41.3.2 interrupt the aes interface has an interrupt line connected to the interrupt controller. handling the aes interrupt requires programming the interrupt controller before configuring the aes.
942 sam4cp [datasheet] 43051e?atpl?08/14 41.4 functional description the advanced encryption standard (aes) specifies a fips-approved cryptographic algorithm that can be used to protect electronic data. the aes algorithm is a symmetric block cipher that can encrypt (encipher) and decrypt (decipher) information. encryption converts data to an unintelligible form called ciphertext. decrypting the ciphertext converts the data back into its original form, called plaintext. the cipher bit in the aes mode register (aes_mr) allows selection between the encryption and the decryption processes. the aes is capable of using cryptographic keys of 128/192/256 bits to encrypt and decrypt data in blocks of 128 bits. this 128-bit/192-bit/256-bit key is defined in the key registers (aes_keywrx). the input to the encryption processes of the cbc, cfb, and ofb modes includes, in addition to the plaintext, a 128-bit data block called the initialization vector (iv), which must be set in the aes_ivrx. the initialization vector is used in an initial step in the encryption of a message and in the corresponding decryption of the message. the aes_ivrx are also used by the ctr mode to set the counter value. 41.4.1 operation modes the aes supports the following modes of operation: ? ecb: electronic code book. ? cbc: cipher block chaining. ? ofb: output feedback. ? cfb: cipher feedback. ? cfb8 (cfb where the length of the data segment is 8 bits). ? cfb16 (cfb where the length of the data segment is 16 bits). ? cfb32 (cfb where the length of the data segment is 32 bits). ? cfb64 (cfb where the length of the data segment is 64 bits). ? cfb128 (cfb where the length of the data segment is 128 bits). ? ctr: counter. ? gcm: galois/counter mode. the data pre-processing, post-processing and data chaining for the concerned modes are automatically performed. refer to the nist special publication 800-38a and nist special publication 800-38d for more complete information. these modes are selected by setting the opmod field in the aes_mr. in cfb mode, five data sizes are possible (8, 16, 32, 64 or 128 bits), configurable by means of the cfbs field in the aes_mr. ( section 41.5.2 ?aes mode register? on page 956 ). in ctr mode, the size of the block counter embedded in the module is 16 bits. therefore, there is a rollover after processing 1 megabyte of data. if the file to be processed is greater than 1 megabyte, this file must be split into fragments of 1 megabyte or less for the first fragment if the initial value of the counter is greater than 0. prior to loading the first fragment into aes_idatarx, aes_ivrx must be fully programmed with the initial counter value. for any fragment, after the transfer is completed and prior to transferring the next fragment, aes_ivrx must be programmed with the appropriate counter value. if the initial value of the counter is greater than 0 and the data buffer size to be processed is greater than 1 megabyte, the size of the first fragment to be processed must be 1 megabyte minus 16x(initial value) to prevent a rollover of the internal 1-bit counter. table 41-1. peripheral ids instance id aes 36
943 sam4cp [datasheet] 43051e?atpl?08/14 to have a sequential increment, the counter value must be programmed with the value programmed for the previous fragment + 2 16 (or less for the first fragment). all aes_ivrx fields must be programmed to take into account the possible carry propagation. 41.4.2 double input buffer the aes_idatarx can be double-buffered to reduce the runtime of large files. this mode allows writing a new message block when the previous message block is being processed. this is only possible when dma accesses are performed (smod = 0x2). the dualbuff bit in aes_mr must be set to 1 to access the double buffer. 41.4.3 start modes the smod field in the aes_mr allows selection of the encryption (or decryption) start mode. 41.4.3.1 manual mode the sequence order is as follows: ? write the aes_mr with all required fields, including but not limited to smod and opmod. ? write the 128-bit/192-bit/256-bit key in the aes_keywrx. ? write the initialization vector (or counter) in the aes_ivrx. note: the aes_ivrx concern all modes except ecb. ? set the bit datrdy (data ready) in the aes interrupt enable register (aes_ier), depending on whether an interrupt is required or not at the end of processing. ? write the data to be encrypted/decrypted in the authorized aes_idatarx (see table 41-2 ). notes: 1. in 64-bit cfb mode, writing to aes_idatar2 and aes_idatar3 is not allowed and may lead to errors in processing. 2. in 32-, 16- and 8-bit cfb modes, writing to aes_idatar1, aes_idatar2 and aes_idatar3 is not allowed and may lead to errors in processing. ? set the start bit in the aes control register (aes_cr) to begin the encryption or the decryption process. ? when processing completes, the datrdy flag in the aes interrupt status register (aes_isr) is raised. if an interrupt has been enabled by setting the datrdy bit in the aes_ier, the interrupt line of the aes is activated. ? when software reads one of the aes_odatarx, the datrdy bit is automatically cleared. table 41-2. authorized input data registers operation mode input data registers to write ecb all cbc all ofb all 128-bit cfb all 64-bit cfb (1) aes_idatar0 and aes_idatar1 32-bit cfb (2) aes_idatar0 16-bit cfb (2) aes_idatar0 8-bit cfb (2) aes_idatar0 ctr all gcm all
944 sam4cp [datasheet] 43051e?atpl?08/14 41.4.3.2 auto mode the auto mode is similar to the manual one, except that in this mode, as soon as the correct number of aes_idatarx is written, processing is automatically started without any action in the aes_cr. 41.4.3.3 pdc mode the peripheral dma controller (pdc) can be used in association with the aes to perform an encryption/decryption of a buffer without any action by software during processing. the field smod in the aes_mr must be configured to 0x2. the sequence order is as follows: ? write the aes_mr with all required fields, including but not limited to smod and opmod. ? write the key in the aes_keywrx. ? write the initialization vector (or counter) in the aes_ivrx. note: the aes_ivrx concern all modes except ecb. ? set the transmit pointer register (aes_tpr) to the address where the data buffer to encrypt/decrypt is stored and the receive pointer register (aes_rpr) where it must be encrypted/decrypted. note: transmit and receive buffers can be identical. ? set the transmit and the receive counter registers (aes_tcr and aes_rcr) to the same value. this value must be a multiple of the data transfer type size (see table 41-3 "data transfer type for the different operation modes" ). note: the same requirements are necessary for the next pointer(s) and counter(s) of the pdc (aes_tnpr, aes_rnpr, aes_tncr, aes_rncr). ? if not already done, set the bit endrx (or rxbuff if the next pointers and counters are used) in the aes_ier, depending on whether an interrupt is required or not at the end of processing. ? enable the pdc in transmission and reception to start the processing (aes_ptcr). when the processing completes, the endrx (or rxbuff) flag in the aes_isr is raised. if an interrupt has been enabled by setting the corresponding bit in the aes_ier, the interrupt line of the aes is activated. when pdc is used, the data size to transfer (byte, half-word or word) depends on the aes mode of operations. this size is automatically configured by the aes. table 41-3. data transfer type for the different operation modes operation mode data transfer type ecb word cbc word ofb word cfb 128-bit word cfb 64-bit word cfb 32-bit word cfb 16-bit half-word cfb 8-bit byte ctr word gcm word
945 sam4cp [datasheet] 43051e?atpl?08/14 41.4.4 last output data mode this mode is used to generate cryptographic checksums on data (mac) by means of cipher block chaining encryption algorithm (cbc-mac algorithm for example). after each end of encryption/decryption, the output data are available either on the aes_odatarx for manual and auto mode or at the address specified in the rec eive buffer pointer for pdc mode (see table 41-4 "last output data mode behavior versus start modes" ). the last output data (lod) bit in the aes_mr allows retrieval of only the last data of several encryption/decryption processes. therefore, there is no need to define a read buffer in pdc mode. this data are only available on the aes_odatarx. 41.4.4.1 manual and auto modes if aes_mr.lod = 0 the datrdy flag is cleared when at least one of the aes_odatarx is read (see figure 41-1 ). figure 41-1. manual and auto modes with aes_mr.lod = 0 if the user does not want to read the aes_odatarx between each encryption/decryption, the datrdy flag will not be cleared. if the datrdy flag is not cleared, the user cannot know the end of the following encryptions/decryptions. if aes_mr.lod = 1 this mode is optimized to process aes cpc-mac operating mode. the datrdy flag is cleared when at least one aes_idatar is written (see figure 41-2 ). no more aes_odatar reads are necessary between consecutive encryptions/decryptions. figure 41-2. manual and auto modes with aes_mr.lod = 1 encryption or decryption process read the aes_odatar x write start bit in aes_cr (manual mode) d atrdy write aes_idatarx register(s) (auto mode) or write aes_idatarx register( s) write start bit in aes_cr (manual mode) write aes_idatarx register(s) (auto mode) or encryption or decryption process d atrdy
946 sam4cp [datasheet] 43051e?atpl?08/14 41.4.4.2 pdc mode if aes_mr.lod = 0 this mode may be used for all aes operating modes except cbc-mac where aes_mr.lod = 1 mode is recommended. the end of the encryption/decryption is indicated when the endrx (or rxbuff) flag is raised (see figure 41-3 ). figure 41-3. pdc transfer with aes_mr.lod = 0 if aes_mr.lod = 1 this mode is optimized to process aes cbc-mac operating mode. the user must first wait for the endtx (or txbufe) flag to be raised, then for datrdy to ensure that the encryption/decryption is completed (see figure 41-4 ). in this case, no receive buffers are required. the output data are only available on the aes_odatarx. figure 41-4. pdc transfer with aes_mr.lod = 1 enable pdc channels (receive and transmit channels) multiple encryption or decryption processes endrx (or rxbuff) e ndtx (or txbufel) message fully processe d (cipher or decipher) last block can be read write accesses into aes_idatarx read accesses into aes_odatarx datrdy enable pdc channels (receive and transmit channels) multiple encryption or decryption processes e ndtx (or txbufe) message fully processe d (cipher or decipher) mac result can be read write accesses into aes_idatarx message fully transferred
947 sam4cp [datasheet] 43051e?atpl?08/14 table 41-4 summarizes the different cases. notes: 1. depending on the mode, there are other ways of clearing the datrdy flag. see ?aes interrupt status register? on page 961 . warning: in pdc mode, reading the aes_odatarx before the last data transfer may lead to unpredictable results. 41.4.5 galois counter mode (gcm) 41.4.5.1 description gcm comprises the aes engine in ctr mode along with a universal hash function (ghash engine) that is defined over a binary galois field to produce a message authentication tag (the aes ctr engine and the ghash engine are depicted in figure 41-5, ?gcm block diagram? ). the ghash engine processes data packets after the aes oper ation. gcm provides assurance of the confidentiality of data through the aes counter mode of operation for encryption. authenticity of the confidential data is assured through the ghash engine. gcm can also provide assurance of data that is not encrypted. refer to the nist special publication 800-38d recommendation for more complete information. gcm can be used with or without the pdc master. messages may be processed as a single complete packet of data or they may be broken into multiple packets of data over time. gcm processing is computed on 128-bit input data fields. there is no support for unaligned data. the aes key length can be whatever length is supported by the aes module. the recommended programming procedure when using pdc is described in section 41.4.5.3 . table 41-4. last output data mode behavior versus start modes sequence manual and auto modes pdc mode aes_mr.lod = 0 aes_mr.lod = 1 aes_mr.lod = 0 aes_mr.lod = 1 datrdy flag clearing condition (1) at least one aes_odatar must be read at least one aes_idatar must be written not used managed by the pdc encrypted/decrypted data result location in the aes_odatarx in the aes_odatarx at the address specified in the aes_rpr in the aes_odatarx end of encryption/decryption notification datrdy datrdy endrx (or rxbuff) endtx (or txbufe) then datrdy
948 sam4cp [datasheet] 43051e?atpl?08/14 figure 41-5. gcm block diagram 41.4.5.2 key writing and automatic hash subkey calculation whenever a new key (aes_keywrx) is written to the hardware, two automatic actions are processed: ? gcm hash subkey h generation - the gcm hash subkey ( h ) is automatically generated. the gcm hash subkey generation must be complete before doing any other action. the datrdy bit of the aes_isr indicates when the subkey generation is complete (with interrupt if configured). the gcm hash subkey calculation is processed with the formula h = cipher (key, <128 bits to zero>. the generated gcm h value is then available in the aes_gcmhrx. if the application software requires a specific hash subkey, the automatically generated h value can be overwritten in the aes_gcmhrx. the aes_gcmhrx can be written after the end of the hash subkey generation (see aes_isr.datrdy) and prior to starting the input data feed. ? aes_ghashrx clear - the aes_ghashrx are automatically cleared. if a hash initial value is needed for the ghash it must be written to the aes_ghashrx: ? after a write to aes_keywrx, if any ? before starting the input data feed ghash engine aes ctr engine counter 1 counter 0 counter n incr 32 incr 32 plaintext 1 auth tag(t) len(aad) || len(c) plaintext n ciphertext 1 ciphertext n gf 128 mult(h) gf 128 mult(h) gf 128 mult(h) gf 128 mult(h) cipher(key) cipher(key) cipher(key) (aes_aadlenr, aes_clenr) (aes_tagrx) (aes_ghashrx) (aes_ivrx) (aes_ctrr) (aes_idatarx) (aes_idatarx) (aes_ctrr) (aes_ghashrx) aad 1 gf 128 mult(h) (aes_gcmhrx) (1) aad n (aes_ghashrx) (aes_idatarx) (aes_idatarx) (aes_keywrx) notes: 1. optional
949 sam4cp [datasheet] 43051e?atpl?08/14 41.4.5.3 gcm processing gcm processing comprises three phases: 1. processing the additional authenticated data (aad), hash computation only. 2. processing the ciphertext (c), hash computation + ciphering/deciphering. 3. generating the tag using length of aad, length of c and j 0 , (see nist documentation for details). the tag generation can be done either automatically, after the end of aad/c processing if tag_en bit is set in the aes_mr or done manually, using th e ghash field in aes_ghashrx (see section 41.4.5.3.1 and section 41.4.5.3.4 for details). 41.4.5.3.1 processing a complete message with tag generation use this procedure only if j 0 four lsb bytes 0xffffffff. note: in the case where j 0 four lsb bytes = 0xffffffff or if the value is unknown, use the procedure described in ?processing a complete message without tag generation? followed by the procedure in ?manual gcm tag generation? . figure 41-2. full message alignment to process a complete message with tag generation, perform the following steps: 1. in aes_mr set opmod to gcm and gtagen to ?1? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bit of aes_isr is set (gcm hash subkey generation com- plete), use interrupt if needed. see section section 41.4.5.2 ?key writing and automatic hash subkey calculation? for details. 3. calculate the j 0 value as described in nist documentation j 0 = iv || 0 31 || 1 when len( iv )=96 and j 0 =ghash h ( iv || 0 s +64 || [len( iv )] 64 ) if len( iv ) 96. see section 41.4.5.3.5 ?processing a message with only aad (ghashh)? for j 0 generation. 4. set iv in aes_ivrx registers with inc32 (j 0 ) (j 0 + 1 on 32 bits). 5. set aadlen field in aes_aadlenr and clen field in aes_clenr. 6. fill the idata field of aes_idatarx with the message to process according to the smod configuration used. if manual mode or auto mode is used, the datrdy bit indicates when the data has been processed (however, no output data are generated when processing aad). 7. wait for tagrdy to be set (use interrupt if needed), then read the tag field of aes_tagrx to obtain the authen- tication tag of the message. 41.4.5.3.2 processing a complete message without tag generation processing a message without generating the tag can be used to customize the tag generation, or to process a fragmented message. to manually generate the gcm tag see section 41.4.5.3.4 . to process a complete message without tag generation, perform the following steps: 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bit of aes_isr is set (gcm hash subkey generation com- plete), use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or overwritten with specific value in the aes_gcmhrx (see section section 41.4.5.2 ?key writing and auto- matic hash subkey calculation? for details). aad c (text) 16-byte boundaries padding paddin g aadlen clen
950 sam4cp [datasheet] 43051e?atpl?08/14 3. calculate the j 0 value as described in nist documentation j 0 = iv || 0 31 || 1 when len( iv )=96 and j 0 =ghash h ( iv || 0 s +64 || [len( iv )] 64 ) if len( iv ) 96. see section 41.4.5.3.5 ?processing a message with only aad (ghashh)? for j 0 generation example when len( iv ) 96. 4. set iv in aes_ivrx registers with inc32 (j 0 ) (j 0 + 1 on 32 bits). 5. set aadlen field in aes_aadlenr and clen field in aes_clenr. 6. fill the idata field of aes_idatarx with the message to process according to the smod configuration used. if manual mode or auto mode is used, the datrdy bit indicates when the data have been processed (however, no output data are generated when processing aad). 7. make sure the last output data have been read if clen 0 (or wait for datrdy), then read the ghash field of aes_ghashrx to obtain the hash value after the last processed data. 41.4.5.3.3 processing a fragmented message without tag generation if needed, a message can be processed by fragments, in such case automatic gcm tag generation is not supported. to process a message by fragments, perform the following steps: ? first fragment: 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait for datrdy bit of aes_isr to be set (gcm hash subkey generation com- plete), use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or overwritten with specific value in the aes_gcmhrx (see section section 41.4.5.2 ?key writing and auto- matic hash subkey calculation? for details). 3. calculate the j 0 value as described in nist documentation j 0 = iv || 0 31 || 1 when len( iv )=96 and j 0 =ghash h ( iv || 0 s +64 || [len( iv )] 64 ) if len( iv ) 96. see section 41.4.5.3.5 ?processing a message with only aad (ghashh)? for j 0 generation example when len( iv ) 96. 4. set iv in aes_ivrx registers with inc32 (j 0 ) (j 0 + 1 on 32 bits). 5. set aadlen field in aes_aadlenr and clen field in aes_clenr according to the length of the first fragment, or set the fields with the full message length, both configurations work. 6. fill the idata field of aes_idatarx with the first fragment of the message to process (aligned on 16-byte boundary) according to the smod configuration used. if manual mode or auto mode is used the datrdy bit indi- cates when the data have been processed (however, no output data are generated when processing aad). 7. make sure the last output data have been read if the fragment ends in c phase (or wait for datrdy if the fragment ends in aad phase), then read the ghash field of aes_ghashrx to obtain the value of the hash after the last processed data and finally read the ctr field of the aes_ctr to obtain the value of the ctr encryption counter (not needed when the fragment ends in aad phase). ? next fragment (or last fragment): 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bit of aes_isr is set (gcm hash subkey generation com- plete), use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or overwritten with specific value in the aes_gcmhrx ( see section section 41.4.5.2 ?key writing and auto- matic hash subkey calculation? for details). 3. set iv in aes_ivrx with: ? if the first block of the fragment is a block of additional authenticated data, set iv in aes_ivrx with the j 0 initial value. ? if the first block of the fragment is a block of plaintext data, set iv in aes_ivrx with a value constructed as follows: ?lsb 96 (j 0 ) || ctr? value, (96 bit lsb of j 0 concatenated with saved ctr value from previous fragment). 4. set aadlen field in aes_aadlenr and clen field in aes_clenr according to the length of the current fragment, or set the fields with the remaining message length, both configurations work. 5. fill the ghash field of aes_ghashrx with the value stored after the previous fragment.
951 sam4cp [datasheet] 43051e?atpl?08/14 6. fill the idata field of aes_idatarx with the current fragment of the message to process (aligned on 16 byte boundary) according to the smod configuration used. if manual mode or auto mode is used, the datrdy bit indi- cates when the data have been processed (however, no output data are generated when processing aad). 7. make sure the last output data have been read if the fragment ends in c phase (or wait for datrdy if the fragment ends in aad phase), then read the ghash field of aes_ghashrx to obtain the value of the hash after the last processed data and finally read the ctr field of the aes_ctr to obtain the value of the ctr encryption counter (not needed when the fragment ends in aad phase). note: step 1 and 2 are required only if the value of the concerned registers has been modified. once the last fragment has been processed, the ghash value will allow manual generation of the gcm tag, see section 41.4.5.3.4 for details. 41.4.5.3.4 manual gcm tag generation this section describes the last steps of the gcm tag generation. the manual gcm tag generation is used to complete the gcm tag generation when the message has been processed without tag generation. note: the message processing without tag generation must be finished before processing the manual gcm tag generation. to generate a gcm tag manually, perform the following steps: processing s = ghash h ( add || 0 v || c || 0 u || [len( add )] 64 || [len( c )] 64 ): 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait for datrdy bit of aes_isr to be set (gcm hash subkey generation com- plete), use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or overwritten with specific value in the aes_gcmhrx ( see section section 41.4.5.2 ?key writing and auto- matic hash subkey calculation? for details). 3. set aadlen field to 0x10 (16 bytes) in aes_aadlenr and clen field to ?0? in aes_clenr. this will allow running a single ghash h on a 16-byte input data (see figure 41-6 ). 4. fill the ghash field of aes_ghashrx with the state of the ghash field stored at the end of the message processing. 5. fill the idata field of aes_idatarx according to the smod configuration used with ?len(add) 64 || len(c) 64 ? value as described in the nist documentation and wait for datrdy to be set, use interrupt if needed. 6. read the ghash field of aes_ghashrx to obtain the current value of the hash. processing t = gctr k (j 0 , s): 7. in aes_mr set opmod to ctr (configuration as usual for the rest). 8. set the iv field in aes_ivrx with ?j 0 ? value. 9. fill the idata field of aes_idatarx with the ghash value read at step 6 and wait for datrdy to be set (use interrupt if needed). 10. read the odata field of aes_odatarx to obtain the gcm tag value. note: step 4 is optional if the ghash field is to be filled with value ?0? (0 length packet for instance).
952 sam4cp [datasheet] 43051e?atpl?08/14 41.4.5.3.5 processing a message with only aad (ghash h ) figure 41-6. single ghash h block diagram (aadlen ? 0x10 and clen = 0) it is possible to process a message with only aad setting the clen field to ?0? in the aes_clenr, this can be used for j 0 generation when len(iv) 96 for instance. example: processing j 0 when len(iv) 96. to process j 0 = ghash h ( iv || 0 s +64 || [len( iv )] 64 ) perform the following steps: 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set keyw in aes_keywrx and wait until datrdy bit of aes_isr is set (gcm hash subkey complete), use interrupt if needed. after the gcm hash subkey generation is complete the gcm hash subkey can be read or over- written with specific value in the aes_gcmhrx ( see section section 41.4.5.2 ?key writing and automatic hash subkey calculation? for details). 3. set aadlen field with ?len( iv || 0 s +64 || [len( iv )] 64 )? in aes_aadlenr and clen field to ?0? in aes_clenr. this will allow running a ghash h only. 4. fill the idata field of aes_idatarx with the message to process ( iv || 0 s +64 || [len( iv )] 64 ) according to the smod configuration used. if manual mode or auto mode is used, the datrdy bit indicates when a ghash h step is over, use interrupt if needed. 5. read the ghash field of aes_ghashrx to obtain the j 0 value. note: the ghash value can be overwritten at any time by writing the ghash field value of aes_ghashrx, used to perform a ghash h with an initial value for ghash (write ghash field between step 3 and step 4 in this case). 41.4.5.3.6 processing a single gf 128 multiplication the aes can also be used to process a single multiplication in the galois field on 128 bits (gf 128 ) using a single ghash h with custom h value (see figure 41-6 ). to run a gf 128 multiplication (a x b) perform the following steps: 1. in aes_mr set opmod to gcm and gtagen to ?0? (configuration as usual for the rest). 2. set aadlen field with 0x10 (16 bytes) in aes_aadlenr and clen field to ?0? in aes_clenr. this will allow running a single ghash h . 3. fill the h field of the aes_gcmhrx with b value. 4. fill the idata field of aes_idatarx with the a value according to the smod configuration used. if manual mode or auto mode is used, the datrdy bit indicates when a ghash h computation is over, use interrupt if needed. 5. read the ghash field of aes_ghashrx to obtain the result. note: ghash field of aes_ghashrx can be initialized with a value c between step 3 and step 4 to run a ((a xor c) x b) gf 128 multiplication. idata ghash ghash gf 128 mult(h)
953 sam4cp [datasheet] 43051e?atpl?08/14 41.4.6 security features 41.4.6.1 unspecified register access detection when an unspecified register access occurs, the urad flag in the aes_isr is raised. its source is then reported in the unspecified register access type (urat) field. only the last unspecified register access is available through the urat field. several kinds of unspecified register accesses can occur: ? input data register written during the data processing when smod = idatar0_start. ? output data register read during data processing. ? mode register written during data processing. ? output data register read during sub-keys generation. ? mode register written during sub-keys generation. ? write-only register read access. the urad bit and the urat field can only be reset by the swrst bit in the aes_cr. 41.5 advanced encryption standard (aes) user interface table 41-5. register mapping offset register name access reset 0x00 control register aes_cr write-only ? 0x04 mode register aes_mr read/write 0x0 0x08 - 0x0c reserved ??? 0x10 interrupt enable register aes_ier write-only ? 0x14 interrupt disable register aes_idr write-only ? 0x18 interrupt mask register aes_imr read-only 0x0 0x1c interrupt status register aes_isr read-only 0x0000001e 0x20 key word register 0 aes_keywr0 write-only ? 0x24 key word register 1 aes_keywr1 write-only ? 0x28 key word register 2 aes_keywr2 write-only ? 0x2c key word register 3 aes_keywr3 write-only ? 0x30 key word register 4 aes_keywr4 write-only ? 0x34 key word register 5 aes_keywr5 write-only ? 0x38 key word register 6 aes_keywr6 write-only ? 0x3c key word register 7 aes_keywr7 write-only ? 0x40 input data register 0 aes_idatar0 write-only ? 0x44 input data register 1 aes_idatar1 write-only ? 0x48 input data register 2 aes_idatar2 write-only ? 0x4c input data register 3 aes_idatar3 write-only ? 0x50 output data register 0 aes_odatar0 read-only 0x0 0x54 output data register 1 aes_odatar1 read-only 0x0 0x58 output data register 2 aes_odatar2 read-only 0x0
954 sam4cp [datasheet] 43051e?atpl?08/14 0x5c output data register 3 aes_odatar3 read-only 0x0 0x60 initialization vector register 0 aes_ivr0 write-only ? 0x64 initialization vector register 1 aes_ivr1 write-only ? 0x68 initialization vector register 2 aes_ivr2 write-only ? 0x6c initialization vector register 3 aes_ivr3 write-only ? 0x70 additional authenticated data length register aes_aadlenr read/write ? 0x74 plaintext/ciphertext length register aes_clenr read/write ? 0x78 gcm intermediate hash word register 0 aes_ghashr0 read/write ? 0x7c gcm intermediate hash word register 1 aes_ghashr1 read/write ? 0x80 gcm intermediate hash word register 2 aes_ghashr2 read/write ? 0x84 gcm intermediate hash word register 3 aes_ghashr3 read/write ? 0x88 gcm authentication tag word register 0 aes_tagr0 read-only ? 0x8c gcm authentication tag word register 1 aes_tagr1 read-only ? 0x90 gcm authentication tag word register 2 aes_tagr2 read-only ? 0x94 gcm authentication tag word register 3 aes_tagr3 read-only ? 0x98 gcm encryption counter value register aes_ctrr read-only ? 0x9c gcm h world register 0 aes_gcmhr0 read/write ? 0xa0 gcm h world register 1 aes_gcmhr1 read/write ? 0xa4 gcm h world register 2 aes_gcmhr2 read/write ? 0xa8 gcm h world register 3 aes_gcmhr3 read/write ? 0xac - 0xfc reserved ??? 0x100 - 0x124 reserved for the pdc ??? table 41-5. register mapping (continued) offset register name access reset
955 sam4cp [datasheet] 43051e?atpl?08/14 41.5.1 aes control register name: aes_cr address: 0x40000000 access: write-only ? start: start processing 0: no effect. 1: starts manual encryption/decryption process. ? swrst: software reset 0: no effect. 1: resets the aes. a software triggered hardware reset of the aes interface is performed. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ??????? swrst 76543210 ???????start
956 sam4cp [datasheet] 43051e?atpl?08/14 41.5.2 aes mode register name: aes_mr address: 0x40000004 access: read/write ? cipher: processing mode 0: decrypts data. 1: encrypts data. ? gtagen: gcm automatic tag generation enable 0: automatic gcm tag generation disabled. 1: automatic gcm tag generation enabled. ? dualbuff: dual input buffer ? procdly: processing delay where n = 10 when keysize = 0 n = 12 when keysize = 1 n = 14 when keysize = 2 the processing time represents the number of clock cycles that the aes needs in order to perform one encryption/decryption. note: the best performance is achieved with procdly equal to 0. ? smod: start mode values which are not listed in the table must be considered as ?reserved?. if a pdc transfer is used, configure smod to 0x2. refer to section 41.4.3.3 ?pdc mode? on page 944 for more details. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ckey ? cfbs 15 14 13 12 11 10 9 8 lod opmod keysize smod 76543210 procdly dualbuff ? gtagen cipher value name description 0x0 inactive aes_idatarx cannot be written during processing of previous block 0x1 active aes_idatarx can be written during processing of previous block when smod = 0x2. it speeds up the overall runtime of large files value name description 0x0 manual_start manual mode 0x1 auto_start auto mode 0x2 idatar0_start aes_idatar0 access only auto mode processing time n procdly 1 + ?? ? =
957 sam4cp [datasheet] 43051e?atpl?08/14 ? keysize: key size values which are not listed in the table must be considered as ?reserved?. ? opmod: operation mode values which are not listed in the table must be considered as ?reserved?. for cbc-mac operating mode, please set opmod to cbc and lod to 1. ? lod: last output data mode 0: no effect. after each end of encryption/decryption, the output data are available either on the output data registers (manual and auto modes) or at the address specified in the receive pointer register (aes_rpr) for pdc mode. in manual and auto modes, the datrdy flag is cleared when at least one of the output data registers is read. 1: the datrdy flag is cleared when at least one of the input data registers is written. no more output data register reads is necessary between consecutive encryptions/decryptions (see ?last output data mode? on page 945 ). warning: in pdc mode, reading to the output data registers before the last data encryption/decryption process may lead to unpredictable results. ? cfbs: cipher feedback data size values which are not listed in table must be considered as ?reserved?. ? ckey: key value name description 0x0 aes128 aes key size is 128 bits 0x1 aes192 aes key size is 192 bits 0x2 aes256 aes key size is 256 bits value name description 0x0 ecb ecb: electronic code book mode 0x1 cbc cbc: cipher block chaining mode 0x2 ofb ofb: output feedback mode 0x3 cfb cfb: cipher feedback mode 0x4 ctr ctr: counter mode (16-bit internal counter) 0x5 gcm gcm: galois/counter mode value name description 0x0 size_128bit 128-bit 0x1 size_64bit 64-bit 0x2 size_32bit 32-bit 0x3 size_16bit 16-bit 0x4 size_8bit 8-bit value name description 0xe passwd this field must be written with 0xe the first time that aes_mr is programmed. for subsequent programming of the aes_mr, any value can be written, including that of 0xe. always reads as 0.
958 sam4cp [datasheet] 43051e?atpl?08/14 41.5.3 aes interrupt enable register name: aes_ier address: 0x40000010 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: enables the corresponding interrupt. ? datrdy: data ready interrupt enable ? endrx: end of receive buffer interrupt enable ? endtx: end of transmit buffer interrupt enable ? rxbuff: receive buffer full interrupt enable ? txbufe: transmit buffer empty interrupt enable ? urad: unspecified register access detection interrupt enable ? tagrdy: gcm tag ready interrupt enable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t agrdy 15 14 13 12 11 10 9 8 ??????? urad 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
959 sam4cp [datasheet] 43051e?atpl?08/14 41.5.4 aes interrupt disable register name: aes_idr address: 0x40000014 access: write-only the following configuration values are valid for all listed bit names of this register: 0: no effect. 1: disables the corresponding interrupt. ? datrdy: data ready interrupt disable ? endrx: end of receive buffer interrupt disable ? endtx: end of transmit buffer interrupt disable ? rxbuff: receive buffer full interrupt disable ? txbufe: transmit buffer empty interrupt disable ? urad: unspecified register access detection interrupt disable ? tagrdy: gcm tag ready interrupt disable 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t agrdy 15 14 13 12 11 10 9 8 ??????? urad 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
960 sam4cp [datasheet] 43051e?atpl?08/14 41.5.5 aes interrupt mask register name: aes_imr address: 0x40000018 access: read-only the following configuration values are valid for all listed bit names of this register: 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. ? datrdy: data ready interrupt mask ? endrx: end of receive buffer interrupt mask ? endtx: end of transmit buffer interrupt mask ? rxbuff: receive buffer full interrupt mask ? txbufe: transmit buffer empty interrupt mask ? urad: unspecified register access detection interrupt mask ? tagrdy: gcm tag ready interrupt mask 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t agrdy 15 14 13 12 11 10 9 8 ??????? urad 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
961 sam4cp [datasheet] 43051e?atpl?08/14 41.5.6 aes interrupt status register name: aes_isr address: 0x4000001c access: read-only ? datrdy: data ready 0: output data not valid. 1: encryption or decryption process is completed. datrdy is cleared when a manual encryption/decryption occurs (start bit in aes_cr) or when a software triggered hardware reset of the aes interface is performed (swrst bit in aes_cr). aes_mr.lod = 0: in manual and auto mode, the datrdy flag can also be cleared when at least one of the output data registers is read. in pdc mode, datrdy is set and cleared automatically. aes_mr.lod = 1: in manual and auto mode, the datrdy flag can also be cleared when at least one of the input data registers is written. in pdc mode, datrdy is set and cleared automatically. ? endrx: end of rx buffer 0: the receive counter register has not reached 0 since the last write in aes_rcr or aes_rncr. 1: the receive counter register has reached 0 since the last write in aes_rcr or aes_rncr. note: this flag must be used only in pdc mode with aes_mr.lod bit cleared. ? endtx: end of tx buffer 0: the transmit counter register has not reached 0 since the last write in aes_tcr or aes_tncr. 1: the transmit counter register has reached 0 since the last write in aes_tcr or aes_tncr. note: this flag must be used only in pdc mode with aes_mr.lod bit set. ? rxbuff: rx buffer full 0: aes_rcr or aes_rncr has a value other than 0. 1: both aes_rcr and aes_rncr have a value of 0. note: this flag must be used only in pdc mode with aes_mr.lod bit cleared. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????t agrdy 15 14 13 12 11 10 9 8 urat ? ? ? urad 76543210 ? ? ? txbufe rxbuff endtx endrx datrdy
962 sam4cp [datasheet] 43051e?atpl?08/14 ? txbufe: tx buffer empty 0: aes_tcr or aes_tncr has a value other than 0. 1: both aes_tcr and aes_tncr have a value of 0. note: this flag must be used only in pdc mode with aes_mr.lod bit set. ? urad: unspecified register access detection status 0: no unspecified register access has been detected since the last swrst. 1: at least one unspecified register access has been detected since the last swrst. urad bit is reset only by the swrst bit in the aes_cr. ? urat: unspecified register access: only the last unspecified register access type is available through the urat field. urat field is reset only by the swrst bit in the aes_cr. ? tagrdy: gcm tag ready 0: gcm tag is not valid. 1: gcm tag generation is complete (cleared reading gcm tag, starting another processing or when writing a new key). value name description 0x0 idr_wr_processing input data register written during the data processing when smod = 0x2 mode 0x1 odr_rd_processing output data register read during the data processing 0x2 mr_wr_processing mode register written during the data processing 0x3 odr_rd_subkgen output data register read during the sub-keys generation 0x4 mr_wr_subkgen mode register written during the sub-keys generation 0x5 wor_rd_access write-only register read access
963 sam4cp [datasheet] 43051e?atpl?08/14 41.5.7 aes key word register x name: aes_keywrx address: 0x40000020 access: write-only ? keyw: key word the four/six/eight 32-bit key word registers set the 128-bit/192-bit/256-bit cryptographic key used for aes encryption/decrypti on. aes_keywr0 corresponds to the first word of the key and respectively aes_keywr3/aes_keywr5/aes_keywr7 to the last one. whenever a new key (aes_keywrx) is written to the hardware two automatic actions are processed: ? gcm hash subkey generation ? aes_ghashrx clear (see section 41.4.5.2 for details). these registers are write-only to prevent the key from being read by another application. 31 30 29 28 27 26 25 24 keyw 23 22 21 20 19 18 17 16 keyw 15 14 13 12 11 10 9 8 keyw 76543210 keyw
964 sam4cp [datasheet] 43051e?atpl?08/14 41.5.8 aes input data register x name: aes_idatarx address: 0x40000040 access: write-only ? idata: input data word the four 32-bit input data registers set the 128-bit data block used for encryption/decryption. aes_idatar0 corresponds to the first word of the data to be encrypted/decrypted, and aes_idatar3 to the last one. these registers are write-only to prevent the input data from being read by another application. 31 30 29 28 27 26 25 24 idata 23 22 21 20 19 18 17 16 idata 15 14 13 12 11 10 9 8 idata 76543210 idata
965 sam4cp [datasheet] 43051e?atpl?08/14 41.5.9 aes output data register x name: aes_odatarx address: 0x40000050 access: read-only ? odata: output data the four 32-bit output data registers contain the 128-bit data block that has been encrypted/decrypted. aes_odatar0 corresponds to the first word, aes_odatar3 to the last one. 31 30 29 28 27 26 25 24 odata 23 22 21 20 19 18 17 16 odata 15 14 13 12 11 10 9 8 odata 76543210 odata
966 sam4cp [datasheet] 43051e?atpl?08/14 41.5.10 aes initialization vector register x name: aes_ivrx address: 0x40000060 access: write-only ? iv: initialization vector the four 32-bit initialization vector registers set the 128-bit initialization vector data block that is used by some modes of operation as an additional initial input. aes_ivr0 corresponds to the first word of the initialization vector, aes_ivr3 to the last one. these registers are write-only to prevent the initialization vector from being read by another application. for cbc, ofb and cfb modes, the iv input value corresponds to the initialization vector. for ctr mode, the iv input value corresponds to the initial counter value. note: these registers are not used in ecb mode and must not be written. 31 30 29 28 27 26 25 24 iv 23 22 21 20 19 18 17 16 iv 15 14 13 12 11 10 9 8 iv 76543210 iv
967 sam4cp [datasheet] 43051e?atpl?08/14 41.5.11 aes additional authenticated data length register name: aes_aadlenr address: 0x40000070 access: read/write ? aadlen: additional authenticated data length length in bytes of the additional authenticated data (aad) that is to be processed. note: the maximum byte length of the aad portion of a message is limited to the 32-bit counter length. 31 30 29 28 27 26 25 24 aadlen 23 22 21 20 19 18 17 16 aadlen 15 14 13 12 11 10 9 8 aadlen 76543210 aadlen
968 sam4cp [datasheet] 43051e?atpl?08/14 41.5.12 aes plaintext/ciphertext length register name: aes_clenr address: 0x40000074 access: read/write ? clen: plaintext/ciphertext length length in bytes of the plaintext/ciphertext (c) data that is to be processed. note: the maximum byte length of the c portion of a message is limited to the 32-bit counter length. 31 30 29 28 27 26 25 24 clen 23 22 21 20 19 18 17 16 clen 15 14 13 12 11 10 9 8 clen 76543210 clen
969 sam4cp [datasheet] 43051e?atpl?08/14 41.5.13 aes gcm intermediate hash word register x name: aes_ghashrx [x=0..3] address: 0x40000078 access: read/write ? ghash: intermediate gcm hash word x the four 32-bit intermediate hash word registers expose the intermediate ghash value. may be read to save the current ghash value so processing can later be resumed, presumably on a later message fragment. whenever a new key (aes_keywrx) is written to the hardware two automatic actions are processed: ? gcm hash subkey generation ? aes_ghashrx clear (see section 41.4.5.2 for details.) if an application software specific hash initial value is needed for the ghash it must be written to the aes_ghashrx: ? after a write to aes_keywrx, if any ? prior to starting the input data feed 31 30 29 28 27 26 25 24 ghash 23 22 21 20 19 18 17 16 ghash 15 14 13 12 11 10 9 8 ghash 76543210 ghash
970 sam4cp [datasheet] 43051e?atpl?08/14 41.5.14 aes gcm authentication tag word register x name: aes_tagrx [x=0..3] address: 0x40000088 access: read-only ? tag: gcm authentication tag x the four 32-bit tag registers contain the final 128-bit gcm authentication tag ?t? when gcm processing is complete. tag0 corresponds to the first word, tag3 to the last word. 31 30 29 28 27 26 25 24 tag 23 22 21 20 19 18 17 16 tag 15 14 13 12 11 10 9 8 tag 76543210 tag
971 sam4cp [datasheet] 43051e?atpl?08/14 41.5.15 aes gcm encryption counter value register name: aes_ctrr address: 0x40000098 access: read-only ? ctr: gcm encryption counter reports the current value of the 32-bit gcm counter. 31 30 29 28 27 26 25 24 ctr 23 22 21 20 19 18 17 16 ctr 15 14 13 12 11 10 9 8 ctr 76543210 ctr
972 sam4cp [datasheet] 43051e?atpl?08/14 41.5.16 aes gcm h word register x name: aes_gcmhrx [x=0..3] address: 0x4000009c access: read/write ? h: gcm h word x the four 32-bit h word registers contain the 128-bit h gcm hash subkey h value. whenever a new key (aes_keywrx) is written to the hardware two automatic actions are processed: ? gcm hash subkey h generation ? aes_ghashrx clear if the application software requires a specific hash subkey, the automatically generated h value can be overwritten in the aes_gcmhrx (see section 41.4.5.2 for details). the choice of a gcm hash subkey h by a write in the aes_gcmhrx permits ? choosing the gcm hash subkey h for ghash operations. ? choosing one operand to process a single gf128 multiply. 31 30 29 28 27 26 25 24 h 23 22 21 20 19 18 17 16 h 15 14 13 12 11 10 9 8 h 76543210 h
973 sam4cp [datasheet] 43051e?atpl?08/14 42. integrity check monitor (icm) 42.1 description the integrity check monitor (icm) is a dma controller that performs hash calculation over multiple memory regions through the use of transfer descriptors located in memory (icm descriptor area). the hash function is based on the secure hash algorithm (sha). the icm controller integrates two modes of operation. the first one is used to hash a list of memory regions and save the digests to memory (icm hash area). the second operation mode is an active monitoring of the memory. in that mode, the hash function is evaluated and compared to the digest located at a predefined memory address (icm hash area). if a mismatch occurs, an interrupt is raised. see figure 42-1 for an example of four-region monitoring. hash and descriptor area s are located in memory inst ance i2, and the four regions are split in memory instances i0 and i1. the icm sha engine is compliant with the american fips (federal information processing standard) publication 180-2 specification. the following terms are concise definitions of the icm concepts used throughout this document: ? region: a partition of instruction or data memory space. ? region descriptor: a data structure stored in memory, defining region attributes. ? region attributes: region start address, region size, region sha engine processing mode, write back or compare function mode. ? context registers: a set of icm non-memory-mapped, internal registers which are automatically loaded, containing the attributes of the region being processed. ? main list: a list of region descriptors. each element associates the start address of a region with a set of attributes. ? secondary list: a linked list defined on a per region basis that describes the memory layout of the region (when the region is non contiguous). ? hash area: predefined memory space where the region hash results (digest) are stored. figure 42-1. four-region monitoring example memory region 0 memory region 1 memory region 2 memory region 3 icm processor interrupt controller icm descriptor area icm hash area memory i0 memory i1 memory i2 system interconnect
974 sam4cp [datasheet] 43051e?atpl?08/14 42.2 embedded characteristics ? master dma interface. ? supports up to 4 non-contiguous memory region monitoring. ? supports block gathering through the use of linked list. ? supports secure hash algorithm (sha1, sha224, sha256). ? compliant with fips publication 180-2. ? configurable processing period: ? when sha1 algorithm is processed, the runtime period is either 85 or 209 clock cycles. ? when sha256 or sha224 algorithm is processed, the runtime period is either 72 or 194 clock cycles. ? programmable bus burden. 42.3 block diagram figure 42-2. integrity check monitor block diagram 42.4 product dependencies 42.4.1 power management the peripheral clock is not continuously provided to the icm. the programmer must first enable the icm clock in the power management controller (pmc) before using the icm. 42.4.2 interrupt the icm interface has an interrupt line connected to the interrupt controller. handling the icm interrupt requires programming the interrupt controller before configuring the icm. integrity scheduler sha hash engine host interface context registers monitoring fsm config registers master dma interface apb bus layer
975 sam4cp [datasheet] 43051e?atpl?08/14 42.5 functional description the integrity check monitor (icm) is a dma controller that performs sha-based memory hashing over memory regions. as shown in figure 42-2 , it integrates a dma interface, a monitoring finite state machine (fsm), an integrity scheduler, a set of context registers, a sha engine, an apb interface and configuration registers. when the icm module is enabled, it sequentially retrieves a circular list of region descriptors from the memory (main list described in figure 42-3 ). up to four regions may be monitored. each region descriptor is composed of four words indicating the layout of the memory region (see figure 42-4 ). it also contains the hashing engine configuration on a per region basis. as soon as the descriptor is loaded from the memory and context registers are updated with the data structure, the hashing operation starts. a programmable number of blocks (see trsize field of the icm_rctrl structure member) is transferred from the memory to the sha engine. when the desired number of blocks have been transferred, the digest is whether moved to memory (write-back function) or compared with a digest reference located in the system memory (compare function). if a digest mismatch occurs, an interrupt is triggered if unmasked. the icm module passes through the region descriptor list until the end of the list marked by an end of list bit set to one. to continuously monitor the list of regions, the wrap bit must be set to one in the last data structure. figure 42-3. icm region descriptor and hash areas table 42-1. peripherals ids instance id icm 34 icm descriptor area - contiguous r ead-only memory region 0 descriptor region 1 descriptor region n descriptor wrap=1 wrap=0 wrap=0 infinite loop when wrap bit is set end of region 0 end of region 1 list end of region n region 0 hash region 1 hash region n hash icm hash area - contiguous read-write once memory main list secondary list
976 sam4cp [datasheet] 43051e?atpl?08/14 each region descriptor supports gathering of data through the use of the secondary list. unlike the main list, the secondary list cannot modify the configuration attributes of the region. when the end of the secondary list has been encountered, the icm returns to the main list. memory integrity monitoring can be considered as a background service and the mandatory bandwidth shall be very limited. in order to limit the icm memory bandwidth, use the bbc field of the icm_cfg register to control icm memory load. figure 42-4. region descriptor the icm integrates a secure hash algorithm engine (sha). this module requires a message padded according to fips180-2 specification. the sha module produces an n-bit message digest each time a block is read and a processing period ends. n is 160 for sha1, 224 for sha224, 256 for sha256. 42.5.1 icm region descriptor structure the icm region descriptor area is a contiguous area of system memory that the controller and the processor can access. when the icm controller is activated, the controller performs a descriptor fetch operation at *(icm_dscr) address. if the main list contains more than one descriptor (i.e. more than one region is to be monitored), the fetch address is *(icm_dscr) + (rid<<4) where rid is the region identifier. end of region 0 i cmdscr region 0 descriptor region 1 descriptor region addr region cfg region ctrl region next 0x000 0x004 0x008 0x00c optional region 0 secondary list region addr unused region ctrl region next 0x000 0x004 0x008 0x00c region 2 descriptor region 3 descriptor main list table 42-2. region descriptor structure (main list) address structure member name icm_dscr+0x000+rid*(0x10) icm region start address icm_raddr icm_dscr+0x004+rid*(0x10) icm region configuration icm_rcfg icm_dscr+0x008+rid*(0x10) icm region control icm_rctrl icm_dscr+0x00c+rid*(0x10) icm region next address icm_rnext
977 sam4cp [datasheet] 43051e?atpl?08/14 42.5.1.1 icm region start address structure member name: icm_raddr address : icm_dscr+0x000+rid*(0x10) access: read/write ? raddr: region start address this field indicates the first byte address of the region. 31 30 29 28 27 26 25 24 raddr 23 22 21 20 19 18 17 16 raddr 15 14 13 12 11 10 9 8 raddr 76543210 raddr
978 sam4cp [datasheet] 43051e?atpl?08/14 42.5.1.2 icm region configuration structure member name: icm_rcfg address : icm_dscr+0x004+rid*(0x10) access: read/write ? cdwbn: compare digest or write back digest 0: the digest is written to the hash area. 1: the digest value is compared to the digest stored in the hash area. ? wrap: wrap command 0: the next region descriptor address loaded is the current region identifier descriptor address incremented by 0x10. 1: the next region descriptor address loaded is icm_dscr. ? eom: end of monitoring 0: the current descriptor does not terminate the monitoring. 1: the current descriptor terminates the main list. wrap bit value has no effect. ? rhien: region hash completed interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? dmien: digest mismatch interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? beien: bus error interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? wcien: wrap condition interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. 31 30 29 28 27 26 25 24 ? ? mrprot 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ? algo ? procdly suien ecien 76543210 wcien beien dmien rhien ? eom wrap cdwbn
979 sam4cp [datasheet] 43051e?atpl?08/14 ? ecien: end bit condition interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? suien: monitoring status updated condition interrupt enable 0: interrupt is disabled, the flag is set when the condition is met. 1: interrupt is enabled, the flag is not set when the condition is met. ? procdly: processing delay when sha1 algorithm is processed, the runtime period is either 85 or 209 clock cycles. when sha256 or sha224 algorithm is processed, the runtime period is either 72 or 194 clock cycles. ? algo: sha algorithm values which are not listed in the table must be considered as ?reserved?. ? mrprot: memory region ahb protection this field indicates the value of hprot ahb signal when the icm retrieves the memory region. value name description 0 shortest sha processing runtime is the shortest one 1 longest sha processing runtime is the longest one value name description 0 sha1 sha1 algorithm processed 1 sha256 sha256 algorithm processed 4 sha224 sha224 algorithm processed
980 sam4cp [datasheet] 43051e?atpl?08/14 42.5.1.3 icm region control structure member name: icm_rctrl address : icm_dscr+0x008+rid*(0x10) access: read/write ? trsize: transfer size for the current chunk of data icm performs a transfer of (trsize+1) blocks of 512 bits. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 trsize 76543210 trsize
981 sam4cp [datasheet] 43051e?atpl?08/14 42.5.1.4 icm region next address structure member name: icm_rnext address : icm_dscr+0x00c+rid*(0x10) access: read/write ? next: region transfer descriptor next address when configured to 0, this field indicates that the current descriptor is the last descriptor of the secondary list, otherwise it points at a new descriptor of the secondary list. 31 30 29 28 27 26 25 24 next 23 22 21 20 19 18 17 16 next 15 14 13 12 11 10 9 8 next 76543210 next ? ?
982 sam4cp [datasheet] 43051e?atpl?08/14 42.5.2 icm hash area the icm hash area is a contiguous area of system memory that the controller and the processor can access. the physical location is configured in the icm hash area start address register. this address is a multiple of 128 bytes. if the cdwbn bit of the context register is cleared (i.e. write back activated), the icm controller performs a digest write operation at the following starting location: *(icm_hash) + (rid<<5), where rid is the current region context identifier. if the cdwbn bit of the context register is set (i.e. digest comparison activated), the icm controller performs a digest read operation at the same address. 42.5.2.1 message digest example considering the following 512 bits message (example given in fips 180-2): ?6162638000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000018? the message is written to memory in a little endian (le) system architecture. the digest is stored at the memory location pointed at by the icm_hash pointer with a region offset. table 42-3. 512 bits message memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 80 63 62 61 0x004 - 0x038 00 00 00 00 0x03c 18 00 00 00 table 42-4. le resulting sha-160 message digest memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 36 3e 99 a9 0x004 6a 81 06 47 0x008 71 25 3e ba 0x00c 6c c2 50 78 0x010 9d d8 d0 9c table 42-5. resulting sha-224 message digest memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 22 7d 09 23 0x004 22 d8 05 34 0x008 77 a4 42 86 0x00c b3 55 a2 bd 0x010 e4 bc ad 2a 0x014 f7 b3 a0 bd 0x018 a7 9d 6c e3
983 sam4cp [datasheet] 43051e?atpl?08/14 considering the following 1024 bits message (example given in fips 180-2): "616263800000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000018" the message is written to memory in a little endian (le) system architecture. 42.5.3 icm sha engine the module can process sha1, sha224, sha256 by means of a configuration field in the sha_mr. 42.5.3.1 processing period the sha engine processing period can be configured. the short processing period allows to allocate bandwidth to the sha module whereas the long processing period allocates more bandwidth on the system bus to other applications. in sha mode, the shortest processing period is 85 clock cycles + 2 clock cycles for start command synchronization. the longest period is 209 clock cycles + 2 clock cycles. in sha256 and sha224 modes, the shortest processing period is 72 clock cycles + 2 clock cycles for start command synchronization. the longest period is 194 clock cycles + 2 clock cycles. 42.5.4 security features when an undefined register access occurs, the urad bit in the interrupt status register (icm_isr) is set if unmasked. its source is then reported in the undefined access status register (icm_uasr). only the first undefined register access is available through the urat field. several kinds of unspecified register accesses can occur: ? unspecified structure member set to one detected when the descriptor is loaded. ? configuration register (icm_cfg) modified during active monitoring. ? descriptor register (icm_dscr) modified during active monitoring. table 42-6. resulting sha-256 message digest memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 bf 16 78 ba 0x004 ea cf 01 8f 0x008 de 40 41 41 0x00c 23 22 ae 5d 0x010 a3 61 03 b0 0x014 9c 7a 17 96 0x018 61 ff 10 b4 0x01c ad 15 00 f2 table 42-7. 1024 bits message memory mapping memory address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 80 63 62 61 0x004 - 0x078 00 00 00 00 0x07c 18 00 00 00
984 sam4cp [datasheet] 43051e?atpl?08/14 ? hash register (icm_hash) modified during active monitoring. ? write-only register read access. the urad bit and the urat field can only be reset by writing a 1 to the icm_ctrl.swrst bit. 42.5.5 icm automatic monitoring mode the ascd bit of the icm_cfg register is used to activate the icm automatic mode. when icm_cfg.ascd is set, the icm performs the following actions: ? the icm controller passes through the main list once with cdwbn bit in the context register at 0 (i.e. write back activated) and eom bit in context register at 0. ? when wrap = 1 in icm_rcfg, the icm controller enters active monitoring with cdwbn bit in context register now set and eom bit in context register cleared. bits cdwbn and eom in the region descriptor structure member (icm_rcfg) have no effect. 42.6 programming the icm for multiple regions table 42-8. region attributes transfer type main list icm_rcfg icm_rnext comments cdwbn wrap eom next single region contiguous list of blocks digest written to memory monitoring disabled 1 item 0 0 1 0 the main list contains only one descriptor.the secondary list is empty for that descriptor. the digest is computed and saved to memory. non contiguous list of blocks digest written to memory monitoring disabled 1 item 0 0 1 secondary list address of the current region identifier the main list contains only one descriptor.the secondary list describes the layout of the non contiguous region. contiguous list of blocks digest comparison enabled monitoring enabled. 1 item 1 1 0 0 when the hash computation is terminated, the digest is compared with the one saved in memory. multiple regions contiguous list of blocks digest written to memory monitoring disabled. more than one item 00 1 for the last, 0 otherwise 0 icm passes through the list once. contiguous list of blocks digest comparison is enabled monitoring is enabled more than one item 1 1 for the last, 0 otherwise 00 icm performs active monitoring of the regions. if a mismatch occurs, an interrupt is raised. non contiguous list of blocks digest is written to memory monitoring is disabled more than one item 00 1 secondary list address icm performs hashing and saves digests to the hash area. non contiguous list of blocks digest comparison is enabled monitoring is enabled. more than one item 11 0 secondary list address icm performs data gathering on a per region basis.
985 sam4cp [datasheet] 43051e?atpl?08/14 42.7 integrity check monitor (icm) user interface table 42-9. register mapping offset register name access reset 0x00 configuration register icm_cfg read/write 0x0 0x04 control register icm_ctrl write-only ? 0x08 status register icm_sr write-only ? 0x0c reserved ? ? ? 0x10 interrupt enable register icm_ier write-only ? 0x14 interrupt disable register icm_idr write-only ? 0x18 interrupt mask register icm_imr read-only 0x0 0x1c interrupt status register icm_isr read-only 0x0 0x20 undefined access status register icm_uasr read-only 0x0 0x24 - 0x2c reserved ? ? ? 0x30 region descriptor area start address register icm_dscr read/write 0x0 0x34 region hash area start address register icm_hash read/write 0x0 0x38 user initial hash value 0 register icm_uihval0 write-only ? ... ... ... ... ... 0x54 user initial hash value 7 icm_uihval7 write-only ? 0x58 - 0xfc reserved ???
986 sam4cp [datasheet] 43051e?atpl?08/14 42.7.1 icm configuration register name: icm_cfg address: 0x40044000 access: read/write ? wbdis: write back disable 0: write back operations are permitted. 1: write back operations are forbidden. context register cdwbn bit is internally set to one and cannot be modified by a linked list element. the cdwbn bit of the icm_rcfg structure member has no effect. when ascd bit of the icm_cfg register is set, wbdis bit value has no effect. ? eomdis: end of monitoring disable 0: end of monitoring is permitted. 1: end of monitoring is forbidden. the eom bit of the icm_rcfg structure member has no effect. ? slbdis: secondary list branching disable 0: branching to the secondary list is permitted. 1: branching to the secondary list is forbidden. the next field of the icm_rnext structure member has no effect and is always considered as zero. ? bbc: bus burden control this field is used to control the burden of the icm system bus. the number of system clock cycles between the end of the curren t processing and the next block transfer is set to 2 bbc . up to 32,768 cycles can be inserted. ? ascd: automatic switch to compare digest 0: automatic mode is disabled. 1: when this mode is enabled, the icm controller automatically swit ches to active monitoring after the first main list pass. bo th cdwbn and wbdis bits have no effect. a one must be written to the eom bit in icm_rcfg to terminate the monitoring. ? dualbuff: dual input buffer 0: dual input buffer mode is disabled. 1: dual input buffer mode is enabled. 31 30 29 28 27 26 25 24 ? ? daprot 23 22 21 20 19 18 17 16 ? ? haprot 15 14 13 12 11 10 9 8 ualgo uihash ? ? dualbuff ascd 76543210 bbc ? slbdis eomdis wbdis
987 sam4cp [datasheet] 43051e?atpl?08/14 ? uihash: user initial hash value 0: the secure hash standard provides the initial hash value. 1: the initial hash value is programmable. field ualgo provides the sha algorithm. the algo field of the icm_rcfg structure member has no effect. ? ualgo: user sha algorithm ? daprot: region descriptor area protection this field indicates the value of the bus protection signals when the icm module performs a read operation in the region descri p- tor area. ? haprot: region hash area protection this field indicates the value of the bus protection signals when the icm module performs a re ad operation in the region hash area. value name description 0 sha1 sha1 algorithm processed 1 sha256 sha256 algorithm processed 4 sha224 sha224 algorithm processed
988 sam4cp [datasheet] 43051e?atpl?08/14 42.7.2 icm control register name: icm_ctrl address: 0x40044004 access: write-only ? enable: icm enable 0: no effect. 1: when set to one, the icm controller is activated. ? disable: icm disable register 0: no effect. 1: the icm controller is disabled. if a region is active, this region is terminated. ? swrst: software reset 0: no effect. 1: resets the icm controller. ? rehash: recompute internal hash 0: no effect. 1: when rehash[ i ] is set to one, region i digest is re-computed. this bit is only available when region monitoring is disabled. ? rmdis: region monitoring disable 0: no effect. 1: when bit rmdis[ i ] is set to one, the monitoring of region with identifier i is disabled. ? rmen: region monitoring enable 0: no effect. 1: when bit rmen[ i ] is set to one, the monitoring of region with identifier i is activated. monitoring is activated by default. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rmen rmdis 76543210 rehash ? swrst disable enable
989 sam4cp [datasheet] 43051e?atpl?08/14 42.7.3 icm status register name: icm_sr address: 0x40044008 access: read-only ? enable: icm controller enable register 0: icm controller is disabled. 1: icm controller is activated. ? rawrmdis: raw region monitoring disabled status 0: raw region monitoring is activated. 1: raw region monitoring is deactivated. ? rmdis: region monitoring disabled status 0: region monitoring is activated. 1: region monitoring is deactivated. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 rmdis rawrmdis 76543210 ??????? enable
990 sam4cp [datasheet] 43051e?atpl?08/14 42.7.4 icm interrupt enable register name: icm_ier address: 0x40044010 access: write-only ? rhc: region hash completed interrupt enable 0: no effect. 1: when rhc[ i ] is set to one, the region i hash completed interrupt is enabled. ? rdm: region digest mismatch interrupt enable 0: no effect. 1: when rdm[ i ] is set to one, the region i digest mismatch interrupt is enabled. ? rbe: region bus error interrupt enable 0: no effect. 1: when rbe[ i ] is set to one, the region i bus error interrupt is enabled. ? rwc: region wrap condition detected interrupt enable 0: no effect. 1: when rwc[ i ] is set to one, the region i wrap condition interrupt is enabled. ? rec: region end bit condition detected interrupt enable 0: no effect. 1: when rec[ i ] is set to one, the region i end bit condition interrupt is enabled. ? rsu: region status updated interrupt disable 0: no effect. 1: when rsu[ i ] is set to one, the region i status updated interrupt is enabled. ? urad: undefined register access detection interrupt enable 0: no effect. 1: the undefined register access interrupt is enabled. 31 30 29 28 27 26 25 24 ??????? urad 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
991 sam4cp [datasheet] 43051e?atpl?08/14 42.7.5 icm interrupt disable register name: icm_idr address: 0x40044014 access: write-only ? rhc: region hash completed interrupt disable 0: no effect. 1: when rhc[ i ] is set to one, the region i hash completed interrupt is disabled. ? rdm: region digest mismatch interrupt disable 0: no effect. 1: when rdm[ i ] is set to one, the region i digest mismatch interrupt is disabled. ? rbe: region bus error interrupt disable 0: no effect. 1: when rbe[ i ] is set to one, the region i bus error interrupt is disabled. ? rwc: region wrap condition detected interrupt disable 0: no effect. 1: when rwc[ i ] is set to one, the region i wrap condition interrupt is disabled. ? rec: region end bit condition detected interrupt disable 0: no effect. 1: when rec[ i ] is set to one, the region i end bit condition interrupt is disabled. ? rsu: region status updated interrupt disable 0: no effect. 1: when rsu[ i ] is set to one, the region i status updated interrupt is disabled. ? urad: undefined register access detection interrupt disable 0: no effect. 1: undefined register access detection interrupt is disabled. 31 30 29 28 27 26 25 24 ??????? urad 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
992 sam4cp [datasheet] 43051e?atpl?08/14 42.7.6 icm interrupt mask register name: icm_imr address: 0x40044018 access: read-only ? rhc: region hash completed interrupt mask 0: when rhc[i] is set to zero, the interrupt is disabled for region i. 1: when rhc[i] is set to one, the interrupt is enabled for region i. ? rdm: region digest mismatch interrupt mask 0: when rdm[i] is set to zero, the interrupt is disabled for region i. 1: when rdm[i] is set to one, the interrupt is enabled for region i. ? rbe: region bus error interrupt mask 0: when rbe[i] is set to zero, the interrupt is disabled for region i. 1: when rbe[i] is set to one, the interrupt is enabled for region i. ? rwc: region wrap condition detected interrupt mask 0: when rwc[i] is set to zero, the interrupt is disabled for region i. 1: when rwc[i] is set to one, the interrupt is enabled for region i. ? rec: region end bit condition detected interrupt mask 0: when rec[i] is set to zero, the interrupt is disabled for region i. 1: when rec[i] is set to one, the interrupt is enabled for region i. ? rsu: region status updated interrupt mask 0: when rsu[i] is set to zero, the interrupt is disabled for region i. 1: when rsu[i] is set to one, the interrupt is enabled for region i. ? urad: undefined register access detection interrupt mask 0: interrupt is disabled. 1: interrupt is enabled. 31 30 29 28 27 26 25 24 ??????? urad 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
993 sam4cp [datasheet] 43051e?atpl?08/14 42.7.7 icm interrupt status register name: icm_isr address: 0x4004401c access: read-only ? rhc: region hash completed when rhc[ i ] is set, it indicates that the icm has completed the region with identifier i . ? rdm: region digest mismatch when rdm[ i ] is set, it indicates that there is a digest comparison mismatch between the hash value of the region with identifier i and the reference value located in the hash area. ? rbe: region bus error when rbe[ i ] is set, it indicates that a bus error has been detected while hashing memory region i . ? rwc: region wrap condition detected when rwc[ i ] is set, it indicates that a wrap condition has been detected. ? rec: region end bit condition detected when rec[ i ] is set, it indicates that an end bit condition has been detected. ? rsu: region status updated detected when rsu[ i ] is set, it indicates that a region status updated condition has been detected. ? urad: undefined register access detection status 0: no undefined register access has been detected since the last swrst. 1: at least one undefined register access has been detected since the last swrst. the urad bit is only reset by the swrst bit in the icm_ctrl register. the urat field in the icm_uasr indicates the unspecified access type. 31 30 29 28 27 26 25 24 ??????? urad 23 22 21 20 19 18 17 16 rsu rec 15 14 13 12 11 10 9 8 rwc rbe 76543210 rdm rhc
994 sam4cp [datasheet] 43051e?atpl?08/14 42.7.8 icm undefined access status register name: icm_uasr address: 0x40044020 access: read-only ? urat: undefined register access trace only the first undefined register access trace is available through the urat field. the urat field is only reset by the swrst bit in the icm_ctrl register. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ????? urat value name description 0 unspec_struct_member unspecified structure member set to one detected when the descriptor is loaded 1 icm_cfg_modified icm_cfg modified during active monitoring 2 icm_dscr_modified icm_dscr modified during active monitoring 3 icm_hash_modified icm_hash modified during active monitoring 4 read_access write-only register read access
995 sam4cp [datasheet] 43051e?atpl?08/14 42.7.9 icm descriptor area start address register name: icm_dscr address: 0x40044030 access: read/write ? dasa: descriptor area start address the start address is a multiple of the total size of the data structure (64 bytes). 31 30 29 28 27 26 25 24 dasa 23 22 21 20 19 18 17 16 dasa 15 14 13 12 11 10 9 8 dasa 76543210 dasa ? ?????
996 sam4cp [datasheet] 43051e?atpl?08/14 42.7.10 icm hash area start address register name: icm_hash address: 0x40044034 access: read/write ? hasa: hash area start address this field points at the hash memory location. the address must be a multiple of 128 bytes. 31 30 29 28 27 26 25 24 hasa 23 22 21 20 19 18 17 16 hasa 15 14 13 12 11 10 9 8 hasa 76543210 hasa ? ? ?????
997 sam4cp [datasheet] 43051e?atpl?08/14 42.7.11 icm user initial hash value register name: icm_uihvalx [x=0..7] address: 0x40044038 access: write-only ? val: initial hash value when uihash bit of imc_cfg register is set, the initial hash value is user-programmable. to meet the desired standard, use the following example values. for icm_uihval0 field: for icm_uihval1 field: for icm_uihval2 field: for icm_uihval3 field: 31 30 29 28 27 26 25 24 val 23 22 21 20 19 18 17 16 val 15 14 13 12 11 10 9 8 val 76543210 val example comment 0x67452301 sha1 algorithm 0xc1059ed8 sha224 algorithm 0x6a09e667 sha256 algorithm example comment 0xefcdab89 sha1 algorithm 0x367cd507 sha224 algorithm 0xbb67ae85 sha256 algorithm example comment 0x98badcfe sha1 algorithm 0x3070dd17 sha224 algorithm 0x3c6ef372 sha256 algorithm example comment 0x10325476 sha1 algorithm 0xf70e5939 sha224 algorithm 0xa54ff53a sha256 algorithm
998 sam4cp [datasheet] 43051e?atpl?08/14 for icm_uihval4 field: for icm_uihval5 field: for icm_uihval6 field: for icm_uihval7 field: example of initial value for sha-1 algorithm: example comment 0xc3d2e1f0 sha1 algorithm 0xffc00b31 sha224 algorithm 0x510e527f sha256 algorithm example comment 0x68581511 sha224 algorithm 0x9b05688c sha256 algorithm example comment 0x64f98fa7 sha224 algorithm 0x1f83d9ab sha256 algorithm example comment 0xbefa4fa4 sha224 algorithm 0x5be0cd19 sha256 algorithm register address address offset / byte lane 0x3 / 31:24 0x2 / 23:16 0x1 / 15:8 0x0 / 7:0 0x000 icm_uihval0 01 23 45 67 0x004 icm_uihval1 89 ab cd ef 0x008 icm_uihval2 fe dc ba 98 0x00c icm_uihval3 76 54 32 10 0x010 icm_uihval4 f0 e1 d2 c3
999 sam4cp [datasheet] 43051e?atpl?08/14 43. classical public key cryptography controller (cpkcc) 43.1 description the classical public key cryptography controller (cpkcc) is an atmel macrocell that processes public key cryptography algorithm calculus in both gf(p) and gf(2^n) fields. the romed cpkcl, the classical public key cryptography library, is the library built on the top of the cpkcc. the classical public key cryptography library includes complete implementation of the following public key cryptography algorithms: ? rsa, dsa: ? modular exponentiation with crt up to 6144 bits. ? modular exponentiation without crt up to 5408 bits. ? prime generation. ? utilities: gcd/modular inverse, divide, modular reduction, multiply? ? elliptic curves: ? ecdsa up to 1504 bits. ? point multiply. ? point add/doubling. ? elliptic curves in gf(p) or gf(2^n). ? choice of the curves parameters so compatibility with nist curves or others. ? deterministic random number generation (drng ansi x9.31) for dsa. 43.2 product dependencies 43.2.1 power management the cpkcc is not continuously clocked. the cpckcc int erface is clocked through the power management controller (pmc). 43.2.2 interrupt sources the cpkcc has an interrupt line connected to the nested vector interrupt controller (nvic). handling interrupts requires programming the nvic before configuring the cpkcc. 43.3 functional description the cpkcc macrocell is managed by the cpkcl library available in the rom memory of the sam4cp. the user interface of the cpkcc is not described in this chapter. the usage description of the cpkcc and its associated libr ary is provided in a separat e document. contact an atmel sales representative for further details.
1000 sam4cp [datasheet] 43051e?atpl?08/14 44. true random number generator (trng) 44.1 description the true random number generator (trng) passes the american nist special publication 800-22 and diehard random tests suites. the trng may be used as an entropy source for seeding an nist approved drng (deterministic rng) as required by fips pub 140-2 and 140-3. 44.2 embedded characteristics ? passed nist special publication 800-22 tests suite. ? passed diehard random tests suite. ? may be used as entropy source for seeding an nist approved drng (deterministic rng) as required by fips pub 140-2 and 140-3. ? provides a 32-bit random number every 84 clock cycles. 44.3 block diagram figure 44-1. trng block diagram 44.4 product dependencies 44.4.1 power management the trng interface may be clocked through the power management controller (pmc), thus the programmer must first configure the pmc to enable the trng user interface clock. the user interface clock is independent from any clock that may be used in the logic circuitry used for the source of entropy. the source of entropy can be enabled before enabling the user interface clock. 44.4.2 interrupt the trng interface has an interrupt line connected to the interrupt controller. in order to handle interrupts, the interrupt controller must be programmed before configuring the trng. user interface apb interrupt controller pmc entropy source peripheral clock trng control logic table 44-1. peripheral ids instance id trng 33
1001 sam4cp [datasheet] 43051e?atpl?08/14 44.5 functional description as soon as the trng is enabled in th e control register (trng_cr), the genera tor provides one 32-bit value every 84 clock cycles. interrupt trng_int can be enabled in the trng_ier (respectively disabled in the trng_idr). this interrupt is set when a new random value is available and is cleared when the status register (trng_isr) is read. the flag datrdy of the (trng_isr) is set when the random data is ready to be read out on the 32-bit output data register (trng_odata). the normal mode of operation checks that the status register flag equals 1 before reading the output data register when a 32-bit random value is required by the software application. figure 44-2. trng data generation sequence 44.6 true random number generator (trng) user interface 84 clock cycles 84 clock cycles 84 clock cycles read trng_isr read trng_odata read trng_isr read trng_odata clock trng_int trng_cr enable table 44-2. register mapping offset register name access reset 0x00 control register trng_cr write-only ? 0x10 interrupt enable register trng_ier write-only ? 0x14 interrupt disable register trng_idr write-only ? 0x18 interrupt mask register trng_imr read-only 0x0000_0000 0x1c interrupt status register trng_isr read-only 0x0000_0000 0x50 output data register trng_odata read-only 0x0000_0000
1002 sam4cp [datasheet] 43051e?atpl?08/14 44.6.1 trng control register name: trng_cr address: 0x40048000 access: write-only ? enable: enables the trng to provide random values 0: disables the trng. 1: enables the trng if 0x524e47 (?rng? in ascii) is written in key field at the same time. ? key: security key 31 30 29 28 27 26 25 24 key 23 22 21 20 19 18 17 16 key 15 14 13 12 11 10 9 8 key 76543210 ??????? enable value name description 0x524e47 passwd writing any other value in this field aborts the write operation.
1003 sam4cp [datasheet] 43051e?atpl?08/14 44.6.2 trng interrupt enable register name: trng_ier address: 0x40048010 access: write-only ? datrdy: data ready interrupt enable 0: no effect. 1: enables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????da trdy
1004 sam4cp [datasheet] 43051e?atpl?08/14 44.6.3 trng interrupt disable register name: trng_idr address: 0x40048014 access: write-only ? datrdy: data ready interrupt disable 0: no effect. 1: disables the corresponding interrupt. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????da trdy
1005 sam4cp [datasheet] 43051e?atpl?08/14 44.6.4 trng interrupt mask register name: trng_imr address: 0x40048018 access: read-only reset: 0x0000_0000 ? datrdy: data ready interrupt mask 0: the corresponding interrupt is not enabled. 1: the corresponding interrupt is enabled. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ???????? 76543210 ???????da trdy
1006 sam4cp [datasheet] 43051e?atpl?08/14 44.6.5 trng interrupt status register name: trng_isr address: 0x4004801c access: read-only reset: 0x0000_0000 ? datrdy: data ready 0: output data is not valid or trng is disabled. 1: new random value is completed. datrdy is cleared when this register is read. 31 30 29 28 27 26 25 24 ???????? 23 22 21 20 19 18 17 16 ???????? 15 14 13 12 11 10 9 8 ?????? 76543210 ???????da trdy
1007 sam4cp [datasheet] 43051e?atpl?08/14 44.6.6 trng output data register name: trng_odata address: 0x40048050 access: read-only reset: 0x0000_0000 ? odata: output data the 32-bit output data register contains the 32-bit random data. 31 30 29 28 27 26 25 24 odata 23 22 21 20 19 18 17 16 odata 15 14 13 12 11 10 9 8 odata 76543210 odata
1008 sam4cp [datasheet] 43051e?atpl?08/14 45. sam4cp electrical characteristics 45.1 absolute maximum ratings table 45-1. absolute maximum ratings* *notice: stresses beyond those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. exposure to absolute maximum rating conditions for extended periods may affect device reliability. storage temperature ....................................-55c to + 125c power supply inputs with respect to ground pins: vddcore, vddpll, vddout plc, vddpll plc, vddout an ............................................1.4v vddbu, vddio, vddin, vddlcd, vddin plc, vddin an ...................................................4.0v voltage on digital input pins with respect to ground .............................. -0.3v to vddio +0.3v 45.2 recommended operating conditions table 45-2. recommended operating conditions on power supply inputs symbol parameter conditions min typ max unit vddcore core logic power supply 1.08 1.20 1.32 v vddbu backup region power supply 1.62 3.3 3.6 v vddio i/os power supply 3.0 3.3 3.6 v vddin analog cells (voltage regulators, 10-bit adc, temperature sensor) power supply 2.5 3.3 3.6 v vddlcd lcd output buffers power supply 2.5 ? 3.6 v vddpll plls and main crystal oscillator power supply 1.08 ? 1.32 v vddin plc plc digital regulator input 3.0 3.3 3.6 v vddin an plc analog regulator input 3.0 3.3 3.6 v vddpll plc plc pll power supply 1.08 1.20 1.32 v f mck master clock frequency vddcore @ 1.20v, t a = 85c vddcore @ 1.08v, t a = 85c ?? 120 100 mhz table 45-3. recommended operating conditions on input pins symbol parameter conditions min typ max unit ad [x] in input voltage range on 10-bit adc analog inputs on ad[0..x] 0 ? min (vddin, vddio) v v gpio_in input voltage range on gpios on any pin configured as a digital input 0 ? vddio v
1009 sam4cp [datasheet] 43051e?atpl?08/14 45.3 electrical parameters usage the tables that follow further on in section 45.4 ?i/o characteristics? , section 45.5 ?embedded analog peripherals characteristics? , section 45.6 ?embedded flash characteristics? and section 45.7 ?power supply current consumption? define the limiting values for several electrical parameters. unless otherwise noted, these values are valid over the ambient temperature range t a = [-40c + 85c]. note that these limits may be affected by the board on which the mcu is mounted. particularly, noisy supply and ground conditions must be avoided and care must be taken to provide: ? a pcb with a low impedance ground plane (unbroken ground planes are strongly recommended). ? low impedance decoupling of the mcu power supply inputs. a 100nf ceramic x7r (or x5r) capacitor placed very close to each power supply input is a minimum requirement. see special recommendations regarding integrated analog functions like voltage reference or voltage regulators in corresponding sections. ? low impedance power supply decoupling of external components. this recommendation aims at avoiding current spikes travelling into the pcb ground plane. 45.4 i/o characteristics 45.4.1 i/o dc characteristics the following characteristics are applicable to the operating temperature range: t a = -40c to 85c, unless otherwise specified. table 45-4. recommended thermal operating conditions symbol parameter conditions min typ max unit t a ambient temperature range -40 ? 85 c t j junction temperature range -40 ? 100 r ja junction-to-ambient thermal resistance lqfp 176 package ? 38 ? c / w p d power dissipation t a = 70 oc t a = 85 oc ?? 789 394 mw table 45-5. i/o dc characteristics symbol parameter conditions min typ max unit v il low-level input voltage 3.0v < vddio < 3.6v ? ? 0.3 x vddio v v ih high-level input voltage 3.0v < vddio < 3.6v 0.7 x vddio ? ? v v oh high-level output voltage 3.0v < vddio < 3.6v i oh ~ 0 i oh > 0 (see i oh details below) vddio vddio - 0.4 ?? v v ol low-level output voltage 3.0v < vddio < 3.6v i ol ~ 0 i ol > 0 (see i ol details below) ?? 0 0.4 v
1010 sam4cp [datasheet] 43051e?atpl?08/14 i oh high-level output current pa0,pa29,pb13,pc0,pc5 pins (1) ma vddio = 3.0v; v oh = v vddio - 0.4 vddio = 3.3v; v oh = v vddio - 0.4 vddio = 3.6v; v oh = v vddio - 0.4 ?? -7 -7 -11 other gpio pins, low drive (2) vddio = 3.0v; v oh = v vddio - 0.4 vddio = 3.3v; v oh = v vddio - 0.4 vddio = 3.6v; v oh = v vddio - 0.4 ?? -3 -5 -6 other gpio pins, high drive (2) vddio = 3.0v; v oh = v vddio - 0.4 vddio = 3.3v; v oh = v vddio - 0.4 vddio = 3.6v; v oh = v vddio - 0.4 ?? -6 -8 -8 relaxed mode (3) pa0,pa29,pb13,pc0,pc5 pins (1) vddio = 3.0v; v oh = v vddio - 0.6 vddio = 3.3v; v oh = 2.2v vddio = 3.6v; v oh = 2.4v ?? -12 -22 -26 relaxed mode (3) other gpio pins, low drive (2) vddio = 3.0v; v oh = v vddio - 0.6 vddio = 3.3v; v oh = 2.2v vddio = 3.6v; v oh = 2.4v ?? -5 -12 -13 relaxed mode (3) other gpio pins, high drive (2) vddio = 3.0v; v oh = v vddio - 0.6 vddio = 3.3v; v oh = 2.2v vddio = 3.6v; v oh = 2.4v ?? -10 -20 -24 i ol low-level output current 3.0v < vddio < 3.6v; v ol = 0.4v ma pa0,pa29,pb13,pc0,pc5 pins (1) other gpio pins, low drive (2) other gpio pins, high drive (2) ?? 9 8 10 relaxed mode (3) 3.0v < vddio < 3.6v; v ol = 0.6v pa0,pa29,pb13,pc0,pc5 pins (1) other gpio pins, low drive (2) other gpio pins, high drive (2) ?? 13 10 13 v hys hysteresis voltage hysteresis mode enabled 150 ? ? mv table 45-5. i/o dc characteristics (continued) symbol parameter conditions min typ max unit
1011 sam4cp [datasheet] 43051e?atpl?08/14 notes: 1. these i/o lines have permanent non-programmable maximum drive (maxdrv). 2. refer to ?peripheral signal multiplexing on i/o lines? tables in the section ?peripherals?. 3. relaxed mode applies for cases of higher output current on the i/o lines that override standard v ol and v oh definitions. 45.4.2 i/o ac characteristics criteria used to define the maximum frequency of the i/os: ? output duty cycle (40% - 60%). ? minimum output swing: 100 mv to vddio - 100 mv. ? minimum output swing: 100 mv to vddio - 100 mv. ? addition of rising and falling time inferior to 75% of the period. notes: 1. pin group 1 = pa0, pa29, pb13, pc0, pc5 pins. 2. other pins, low drive settings. 3. other pins, medium drive settings. i il input low leakage current no pull-up or pull-down; v in= gnd; v vddio max. (typ: t a = 25c, max: t a = 85c) - pa0,pa29,pb13,pc0,pc5 pins - pb16,pb17,pb18,pb19,pb20,pb21 pins - other pins ? 12 5 4 57 41 7 na i ih input high leakage current no pull-up or pull-down; v in= vdd; v vddio max. (typ: t a = 25c, max: t a = 85c) - pa0,pa29,pb13,pc0,pc5 pins - pb16,pb17,pb18,pb19,pb20,pb21 pins - other pins ? 15 1.7 5 150 9 14 na r pullup pull-up resistor digital input mode 70 100 130 k r pulldown pull-down resistor 70 100 130 k r odt on-die series termination resistor ? ? 36 ? c pad input capacitance i/o configured as digital input ? ? 5 pf table 45-5. i/o dc characteristics (continued) symbol parameter conditions min typ max unit table 45-6. i/o ac characteristics symbol parameter conditions min max unit freqmax1 pin group 1 (1) maximum output frequency 10 pf v vddio = 3.3v ?70 mhz 30 pf ? 45 freqmax2 pin group 2 (2) maximum output frequency 10 pf v vddio = 3.3v ?35 25 pf ? 15 freqmax3 pin group3 (3) maximum output frequency 10 pf v vddio = 3.3v ?70 25 pf ? 35
1012 sam4cp [datasheet] 43051e?atpl?08/14 table 45-7 provides the input characteristics of the i/o lines with voltage reference to vddio. in particular, these values apply when the xin input is used as a clock input of the device (oscillator set in bypass mode). they do not apply for the xin32 input which is made for slow signals with frequencies up to 50 khz. 45.4.3 spi characteristics figure 45-1. spi master mode with (cpol= ncpha = 0) or (cpol= ncpha= 1) figure 45-2. spi master mode with (cpol = 0 and ncpha=1) or (cpol=1 and ncpha= 0) table 45-7. input characteristics symbol parameter conditions min typ max unit f in input frequency ? ? 50 mhz t in input period 20 ? ? ns t high time at high level 8 ? ? t low time at low level 8 ? ? t r rise time ? ? 2.2 t f fall time ? ? 2.2 t in t low t high t high t r t f v il v ih spck miso mosi spi 2 spi 0 spi 1 spck miso mosi spi 5 spi 3 spi 4
1013 sam4cp [datasheet] 43051e?atpl?08/14 figure 45-3. spi slave mode with (cpol=0 and ncpha=1) or (cpol=1 and ncpha=0) figure 45-4. spi slave mode with (cpol = ncpha = 0) or (cpol= ncpha= 1) 45.4.3.1 maximum spi frequency the formulas that follow give maximum spi frequency in master write and read modes and in slave read and write modes. master write mode the spi is only sending data to a slave device such as an lcd, for example. the limit is given by spi 2 (or spi 5 ) timing. since it gives a maximum frequency above the maximum pad speed (see section 45.4.2 ?i/o ac characteristics? ), the max spi frequency is the one from the pad. master read mode t valid is the slave time response to output data after detecting an spck edge. for atmel spi dataflash (at45db642d), t valid (or t v ) is 12 ns max. in the formula above, f spck max = 40 mhz @ vddio = 3.3v. spck miso mosi spi 6 spi 7 spi 8 npcss spi 12 spi 13 spck miso mosi spi 9 spi 10 spi 11 npcs0 spi 14 spi 15 f spck max 1 spi 0 orspi 3 ?? t valid + -------------------------------------------------------- =
1014 sam4cp [datasheet] 43051e?atpl?08/14 slave read mode in slave mode, spck is the input clock for the spi. the max spck frequency is given by setup and hold timings spi 7 /spi 8 (or spi 10 /spi 11 ). since this gives a frequency well above the pad limit, the limit in slave read mode is given by spck pad. slave write mode t setup is the setup time from the master before sampling data. 45.4.3.2 spi timings note: v vddio from 3.0v to 3.6v, maximum external capacitor = 10pf. note that in spi master mode, the mcu does not sample the data (miso) on the opposite edge where data clocks out (mosi) but the same edge is used as shown in figure 45-1 and figure 45-2 . f spck max 1 2 xs ? pi 6 max orspi 9 max ?? t setup ? + -------------------------------------------- ------------------------------------------- - = table 45-8. spi timings symbol parameter min max unit spi 0 miso setup time before spck rises (master) 15.3 ? ns spi 1 miso hold time after spck rises (master) -3.9 ? ns spi 2 spck rising to mosi delay (master) -5.5 1.5 ns spi 3 miso setup time before spck falls (master) 21.7 ? ns spi 4 miso hold time after spck falls (master) -8.1 ? ns spi 5 spck falling to mosi delay (master) -9.9 -4.2 ns spi 6 spck falling to miso delay (slave) 3.9 13.8 ns spi 7 mosi setup time before spck rises (slave) 0.4 ? ns spi 8 mosi hold time after spck rises (slave) 3.9 ? ns spi 9 spck rising to miso delay (slave) 4.0 14.4 ns spi 10 mosi setup time before spck falls (slave) 1.1 ? ns spi 11 mosi hold time after spck falls (slave) 2.8 ? ns spi 12 npcs setup to spck rising (slave) 3.8 ? ns spi 13 npcs hold after spck falling (slave) -29.9 ? ns spi 14 npcs setup to spck falling (slave) 4.5 ? ns spi 15 npcs hold after spck falling (slave) -28.7 ? ns
1015 sam4cp [datasheet] 43051e?atpl?08/14 45.4.4 usart in spi mode timings timings are given in the following domain: ? v vddio from 3.0v to 3.6v, maximum external capacitor = 10pf . figure 45-5. usart spi master mode figure 45-6. usart spi slave mode: (mode 1 or 2) figure 45-7. usart spi slave mode: (mode 0 or 3) nss spi 0 msb lsb spi 1 cpol=1 cpol=0 miso mosi sck spi 5 spi 2 spi 3 spi 4 spi 4 ? the mosi line is driven by the output pin txd ? the miso line drives the input pin rxd ? the sck line is driven by the output pin sck ? the nss line is driven by the output pin rts sck miso mosi spi 6 spi 7 spi 8 nss spi 12 spi 13 ? the mosi line drives the input pin rxd ? the miso line is driven by the output pin txd ? the sck line drives the input pin sck ? the nss line drives the input pin cts sck miso mosi spi 9 spi 10 spi 11 nss spi 14 spi 15
1016 sam4cp [datasheet] 43051e?atpl?08/14 45.4.4.1 usart spi timings table 45-9. usart spi timings symbol parameter min max units master mode spi 0 sck period 6 / mck ? ns spi 1 input data setup time 0.5 * mck + 1.1 ? ns spi 2 input data hold time 1.5 * mck + 4.8 ? ns spi 3 chip select active to serial clock 1.5 * spck + 0.9 ? ns spi 4 output data setup time - 6.7 7.1 ns spi 5 serial clock to chip select inactive 1 * spck - 6.0 ? ns slave mode spi 6 sck falling to miso 6.8 20.7 ns spi 7 mosi setup time before sck rises 2 * mck + 0.2 ? ns spi 8 mosi hold time after sck rises 4.2 ? ns spi 9 sck rising to miso 8.1 19.8 ns spi 10 mosi setup time before sck falls 2 * mck + 1 ? ns spi 11 mosi hold time after sck falls 5.2 ? ns spi 12 npcs0 setup to sck rising 2,5 * mck - 0.4 ? ns spi 13 npcs0 hold after sck falling 1,5 * mck + 5.5 ? ns spi 14 npcs0 setup to sck falling 2,5 * mck + 0.2 ? ns spi 15 npcs0 hold after sck rising 1,5 * mck + 4.5 ? ns
1017 sam4cp [datasheet] 43051e?atpl?08/14 45.5 embedded analog peripherals characteristics 45.5.1 core voltage regulator notes: 1. current needed to charge external bypass/decoupling capacitor network. 2. a ceramic capacitor must be connected between vddin and the closest gnd pin of the device. this decoupling capacitor is mandatory to reduce inrush current and to improve transient response and noise rejection. 3. to ensure stability, an external output capacitor, c out must be connected between the vddout and the closest gnd pin of the device. the esr (equivalent series resistance) of the capacitor must be in the range of 0.01 to 10 . solid tantalum, and multilayer ceramic capacitors are all suitable as output capacitor. an additional 100nf bypass capacitor between vddout and the closest gnd pin of the device helps decrease output noise and improves the load transient response. table 45-10. core voltage regulator characteristics symbol parameter conditions min typ max unit v vddin supply voltage range (vddin) 2.5 3.3 3.6 v v vddout dc output voltage normal mode standby mode ? 1.2 0 ?v i load maximum dc output current v vddin > 2.5v t j = 100oc ? ? 120 ma acc output voltage total accuracy i load = 0.8 ma to 120 ma v vddin = 2.5v to 3.6v t j = [-40oc to 100oc] -5 ? 5 % i inrush inrush current i load = 0. see note (1) . ? ? 400 ma i vddin current consumption (vddin) normal mode; i load = 0 ma normal mode; i load = 120 ma standby mode; ? 5 500 0.02 1 a c in input decoupling capacitor (2) 1?? f c out output capacitor (3) capacitance esr 0.7 0.01 2.2 10 10 f t on turn on time c out = 2.2 f, v vddout reaches 1.2v (+/- 3%) ? 500 ? s t off turn off time c out = 2.2 f??40ms
1018 sam4cp [datasheet] 43051e?atpl?08/14 45.5.2 plc dc characteristics table 45-11. plc dc characteristics parameter condition symbol rating unit min typ max supply voltage vddio 3.00 3.30 3.60 v h-level input voltage (3.3v cmos) vih 2.0 - vddio+0.3 l-level input voltage (3.3v cmos) vil -0.3 - 0.8 h-level output voltage 3.3v i/o ioh = -100 a voh vddio-0.2 - vddio l-level output voltage 3.3v i/o iol = 100 a vol 0 - 0.2 h-level output v - i characteristics 3.3v i/o vddio=3.30.3 ioh see ?v-i curves ? section ma l-level output v - i characteristics 3.3v i/o vddio=3.30.3 iol see ?v-i curves ? section internal pull-up resistor 3.3v i/o rpu 15 33 70 k internal pull-down resistor 3.3v i/o rpd 15 33 70
1019 sam4cp [datasheet] 43051e?atpl?08/14 45.5.2.1 v-i curves v-i characteristics 3.3v standard cmos io l, m type apply to pins intest3, intest4, agc0, agc3 condition: min process = slow t j = 125c vddio = 3.0v typ process = typical t j = 25c vddio = 3.3v max process = fast t j = -40c vddio = 3.6v apply to pins agc1, agc4 condition: min process = slow t j = 125c vddio = 3.0v typ process = typical t j = 25c vddio = 3.3v max process = fast t j = -40c vddio = 3.6v
1020 sam4cp [datasheet] 43051e?atpl?08/14 apply to pins clkout, txrx0, txrx1, agc2, agc5 condition: min process = slow t j = 125c vddio = 3.0v typ process = typical t j = 25c vddio = 3.3v max process = fast t j = -40c vddio = 3.6v apply to pins emit [0:11] condition: min process = slow t j = 125c vddio = 3.0v typ process = typical t j = 25c vddio = 3.3v max process = fast t j = -40c vddio = 3.6v
1021 sam4cp [datasheet] 43051e?atpl?08/14 45.5.3 automatic power switch 45.5.4 lcd voltage regulator and lcd output buffers the lcd voltage regulator is a complete solution to drive a lcd display. it integrates a low-power ldo regulator with programmable output voltage and some buffers to drive the lcd lines. a 1 f capacitor is required at the ldo regulator output (vddlcd). this regulator can be either set in active (normal) mode, or in bypass mode (hiz mode), or in off mode. ? in normal mode, the vddlcd ldo regulator output can be selected from 2.4v to 3.5v using lcdvrout bits in the supply controller mode register (supc_mr), with the conditions: ? vddlcd ? vddio and, ? vddlcd ? vddin - 150mv. ? in bypass mode (hiz mode), the vddlcd is set in high impedance (through the lcdmode bits in supc_mr register), and can be forced externally. this mode can be used to save the ldo operating current (4 a). ? in off mode, the vddlcd output is pulled down. important: when using an external or the internal voltage regulator, vddio and vddin must be still supplied with the conditions: 2.4v ? vddlcd ? vddio/vddin and vddio/vddin 2.5v. table 45-12. automatic power switch characteristics symbol parameter conditions min typ max unit v it+ positive-going input threshold voltage (vddio) 1.9 ? 2.2 v v it- negative-going input threshold voltage (vddio) 1.8 ? 2.1 v v it_hys threshold hysteresis ? 100 ? mv table 45-13. lcd voltage regulator characteristics symbol parameter conditions min typ max unit v vddin supply voltage range (vddin) 2.5 ? 3.6 v v vddlcd programmable output range see table 45-14 . 2.4 ? 3.5 v output voltage accuracy -10 ? 10 % i vddin current consumption (vddin) ldo enabled ? ? 4 a d vout / d vddin vddlcd variation with vddin ? -50 -70 mv/v i load output current dc or transient load averaged by the external decoupling capacitor ?? 2ma c out output capacitor on vddlcd 1 ? 10 f t on startup time c out = 1 f??1ms table 45-14. vddlcd voltage selection at vddin = 3.6v lcd vrout vddlcd (v) lcd vrout vddlcd (v) lcd vrout vddlcd (v) lcd vrout vddlcd (v) 0 2.86 4 2.57 8 3.45 12 3.16 1 2.79 5 2.50 9 3.38 13 3.09 2 2.72 6 2.43 10 3.31 14 3.02 3 2.64 7 2.36 11 3.23 15 2.95
1022 sam4cp [datasheet] 43051e?atpl?08/14 45.5.5 vddcore brownout detector notes: 1. the product is guaranteed to be functional at v it- figure 45-8. core brownout output waveform figure 45-9. core brownout transfer characteristics table 45-15. lcd buffers characteristics symbol parameter conditions min typ max unit i vddin current consumption (vddin) ldo enabled ? 25 35 a z out buffer output impedance gpio in lcd mode (seg or com) 200 500 1500 c load capacitive output load 10p ? 50n f t r / t f rising or falling time 95% convergence c load = 10pf c load = 50nf ?? 3 225 s table 45-16. core power supply brownout detector characteristics symbol parameter conditions min typ max unit v it- negative-going input threshold voltage (vddcore) (1) 0.98 1 1.04 v v it+ positive-going input threshold voltage (vddcore) 0.8 1.0 1.08 v v hys hysteresis voltage v it+ - v it- ?2550mv t d- v it- detection propagation time vddcore = v it+ to (v it- - 100mv) ? 200 300 ns t on startup time from disabled state to enabled state ? ? 300 s i vddcore current consumption (vddcore) brownout detector enabled ? ? 15 a i vddio current consumption (vddio) brownout detector enabled ? ? 18 a t vddcore v it - v it + bod output t td+ td- vddcore increasing supply vhyst decreasing supply vth- vth+ vth- vth+ bod output
1023 sam4cp [datasheet] 43051e?atpl?08/14 45.5.6 vddcore power-on-reset 45.5.7 vddio supply monitor notes: 1. the average current consumption can be reduced by using the supply monitor in sampling mode. see the section supply controller (supc). 2. v hyst = v th+ - v th- . v th+ are the positive-going input threshold voltage (vddio). table 45-17. core power supply power-on-reset characteristics symbol parameter conditions min typ max unit v it- negative-going input threshold voltage (vddcore) 0.71 0.9 1.02 v v it+ positive-going input threshold voltage (vddcore) 0.8 1.0 1.08 v v hys hysteresis voltage v it+ - v it- ? 60 110 mv t d- v it- detection propagation time vddcore = v it+ to (v it- - 100mv) ??15 s t on startup time vddcore rising from 0 to final value. time to release reset signal. ? ? 300 s i vddcore current consumption (vddcore) ? ? 6 a i vddio current consumption (vddio) ? ? 9 a table 45-18. vddio supply monitor symbol parameter conditions min typ max unit v th- programmable range of negative- going input threshold voltage (vddio) 4 selectable steps 3.0 ? 3.6 v acc v th- accuracy with respect to programmed value -2.5 ? +2.5 % v hyst hysteresis ? 30 40 mv i ddon current consumption (vddio) (1) on with a 100% duty cycle ? 20 40 a t on startup time from off to on ? ? 300 s table 45-19. vddio supply monitor v th- threshold selection digital code threshold typ (v) 1100 3.04 1101 3.16 1110 3.28 1111 3.4
1024 sam4cp [datasheet] 43051e?atpl?08/14 45.5.8 vddbu power-on-reset figure 45-10. zero-power-on reset characteristics 45.5.9 vddio power-on-reset table 45-20. zero-power-on por (backup por) characteristics symbol parameter conditions min typ max unit v th+ positive-going input threshold voltage (vddbu) at startup 1.45 1.53 1.59 v v th- negative-going input threshold voltage (vddbu) 1.35 1.45 1.55 v i vddbu current consumption enabled ? 300 700 na t res reset time-out period 100 240 500 s v it- v it+ vddbu reset table 45-21. zero-power-on por (vddio por) characteristics symbol parameter conditions min typ max unit v th+ positive-going input threshold voltage (vddio) at startup 1.45 1.53 1.59 v v th- negative-going input threshold voltage (vddio) 1.35 1.45 1.55 v i vddio current consumption ? 300 700 na t res reset time-out period 100 240 500 s
1025 sam4cp [datasheet] 43051e?atpl?08/14 45.5.10 oscillator characteristics 45.5.10.1 32 khz rc oscillator 45.5.10.2 4/8/12 mhz rc oscillators notes: 1. frequency range can be configured in the pmc clock generator. table 45-22. 32 khz rc oscillator characteristics symbol parameter conditions min typ max unit v vddbu supply voltage range (vddbu) 1.62 3.3 3.6 v f 0 frequency initial accuracy vddbu = 3.3v, t a = 27c 26 32 39 khz df/dv frequency drift with vddbu vddbu from 1.6v to 3.6v 0.5 1.5 2.5 % / v df/dt frequency drift with temperature t a = [-40c to +27c] ? +8 +17 % t a = [27c to 85c] ? +6 +13 duty duty cycle 48 50 52 % t on startup time ? ? 100 s i ddon current consumption (vddbu) ? 150 300 na table 45-23. 4/8/12 mhz rc oscillators characteristics symbol parameter conditions min typ max unit v vddcore supply voltage range (vddcore) 1.08 1.2 1.32 v f range output frequency range (1) 4 ? 12 mhz acc 4 4 mhz range; total accuracy -40c < t a < +85c ? ? 30 % acc 8 8 mhz range; total accuracy vddcore from 1.08v to 1.32v t a = 25c 0c < t a < +70c -40c < t a < +85c ?? 1.0 3.0 5.0 % acc 12 12 mhz range; total accuracy vddcore from 1.08v to 1.32v t a = 25c 0c < t a < +70c -40c < t a < +85c ?? 1.0 3.0 5.0 % f step frequency trimming step size 8 mhz 12 mhz ? 47 64 ? khz duty duty cycle 45 50 55 % t on startup time, moscrcen from 0 to 1 ? ? 10 s t stab stabilization time on rc frequency change (moscrcf) ?? 5 s i ddon active current consumption (vddcore) 4 mhz 8 mhz 12 mhz ? 50 65 82 68 86 102 a
1026 sam4cp [datasheet] 43051e?atpl?08/14 45.5.10.3 32.768 khz crystal oscillator notes: 1. r s is the series resistor. figure 45-11. 32.768 khz crystal oscillator schematic c lext32k = 2 x ( c crystal ? c para32k ? c pcb / 2). where c pcb is the ground referenced parasitic capacitance of the printed circuit board (pcb) on xin32 and xout32 tracks. as an example, if the crystal is specified for a 12.5pf load, with c pcb = 1pf (on xin32 and on xout32), c lext32k = 2 x (12.5 - 0.7 - 0.5) = 22.6pf table 45-24. 32.768 khz crystal oscillator characteristics symbol parameter conditions min typ max unit v vddbu supply voltage range (vddbu) 1.62 3.3 3.6 v f req operating frequency normal mode with crystal ? ? 32.768 khz duty duty cycle 40 50 60 % t on startup time rs (1) < 50 k rs (1) < 100 k c crystal = 12.5pf c crystal = 6pf c crystal = 12.5pf c crystal = 6pf ?? 900 300 1200 500 ms i ddon current consumption (vddbu) rs (1) < 65 k rs (1) < 100 k rs (1) < 20 k c crystal = 12.5pf c crystal = 6pf c crystal = 6pf c crystal = 6pf ? 450 280 350 220 950 850 1050 ? na p on drive level ? ? 0.1 w r f internal resistor between xin32 and xout32 ? 10 ? m c crystal allowed crystal capacitive load from crystal specification 6 ? 12.5 pf c lext32k external capacitor on xin32 and xout32 ???24pf c para32k internal parasitic capacitance between xin32 and xout32 0.6 0.7 0.8 pf xin32 xout32 c lext32k c lext32k sam4 c para32k c pcb c pcb
1027 sam4cp [datasheet] 43051e?atpl?08/14 table 45-25 below summarizes recommendations for 32.768 khz crystal selection. 45.5.10.4 3 to 20 mhz crystal oscillator notes: 1. see ?crystal oscillator design considerations information? . 2. rs = 100 - 200 ; cs = 2.0 - 2.5pf; cm = 2 - 1.5 ff(typ, worst case) using 1 k serial resistor on xout. 3. rs = 50 - 100 ; cs = 2.0 - 2.5pf; cm = 4 - 3 ff(typ, worst case). 4. rs = 25 - 50 ; cs = 2.5 - 3.0pf; cm = 7 - 5 ff (typ, worst case). 5. rs = 20 - 50 ; cs = 3.2 - 4.0pf; cm = 10 - 8 ff(typ, worst case). table 45-25. recommended crystal characteristics symbol parameter conditions min typ max unit esr equivalent series resistor (r s ) crystal @ 32.768 khz ? 50 100 k c m motional capacitance crystal @ 32.768 khz 0.6 ? 3 ff c shunt shunt capacitance crystal @ 32.768 khz 0.6 ? 2 pf table 45-26. 3 to 20 mhz crystal oscillator characteristics (1) symbol parameter conditions min typ max unit v vddio supply voltage range (vddio) 3.0 3.3 3.6 v v vddpll supply voltage range (vddpll) 1.08 1.2 1.32 v f osc operating frequency range normal mode with crystal 3 16 20 mhz duty duty cycle 40 50 60 % t on startup time 3 mhz, c shunt = 3pf 8 mhz, c shunt = 7pf 16 mhz, c shunt = 7pf with cm = 8ff 16 mhz, c shunt = 7pf with cm = 1.6ff 20 mhz, c shunt = 7pf ?? 14.5 4 1.4 2.5 1 ms i ddon current consumption on vddio on vddpll 3 mhz (2) 8 mhz (3) 16 mhz (4) 20 mhz (5) 3 mhz (2) 8 mhz (3) 16 mhz (4) 20 mhz (5) ? 230 300 390 450 6 12 20 24 350 400 470 560 7 14 23 30 a p on drive level 3 mhz 8 mhz 16 mhz, 20 mhz ?? 15 30 50 w r f internal resistor between xin and xout ? 0.5 ? m c crystal allowed crystal capacitive load from crystal specification 12 ? 18 pf c lext external capacitor on xin and xout ? ? ? 18 pf c lint integrated load capacitance between xin and xout 7.5 9.5 10.5 pf
1028 sam4cp [datasheet] 43051e?atpl?08/14 figure 45-12. 3 to 20 mhz crystal oscillator schematic c lext = 2 x ( c crystal ? c lint ? c pcb / 2). where c pcb is the ground referenced parasitic capacitance of the printed circuit board (pcb) on xin and xout tracks. as an example, if the crystal is specified for a 18pf load, with c pcb = 1pf (on xin and on xout), clext = 2 x (18 - 9.5 - 0.5) = 16pf table 45-27 summarizes the recommendations to be followed when choosing a crystal. table 45-27. recommend crystal characteristics symbol parameter conditions min typ max unit esr equivalent series resistor (rs) fundamental @ 3 mhz fundamental @ 8 mhz fundamental @ 12 mhz fundamental @ 16 mhz fundamental @ 20 mhz ?? 200 100 80 80 50 c m motional capacitance ? ? 8 ff c shunt shunt capacitance ? ? 7 pf xin xout c lext c lint c lext sam4 r = 1k if crystal frequency is lower than 8 mhz c pcb c pcb
1029 sam4cp [datasheet] 43051e?atpl?08/14 45.5.10.5 20 mhz clkea (plc) crystal oscillator characteristics notes: 1. the crystal should be located as close as possible to clkeb and clkea pins. 2. recommended value for cx is 18pf and rs 220 . these values may depend on the specific crystal characteristics. 3. crystal stability/tolerance/ageing values must be selected according to standard prime requirements. table 45-28. plc 20 mhz crystal oscillator characteristics parameter test condition symbol rating unit min typ max crystal oscillator frequency fundamental xtal 20 mhz external oscillator capacitance cx 5 18 30 pf h-level input voltage xvih 2 - vddio +0.3 v l-level input voltage xvil -0.3 - 0.8 external oscillator parallel resistance rp not needed external oscillator series resistance rs 220 clkeb clkea xtal cx cx rs crystal oscillation cell internal output pin oscillation control input pin oscillation circuit input pin oscillation control output pin clkea clkeb
1030 sam4cp [datasheet] 43051e?atpl?08/14 45.5.10.6 crystal oscillator design considerations information when choosing a crystal for the 32768 hz slow clock oscillator or for the 3 - 20 mhz oscillator, several parameters must be taken into account. important parameters are as follows: ? main oscillator input clkout signal is intended to be used as xin (system main oscillator) input. when using an external crystal/oscillator as xin input instead clkout signal, clkout should be switched off by software to minimize noise due to coupling in close pins. ? crystal load capacitance the total capacitance loading the crystal, including the oscillators internal parasitics and the pcb parasitics, must match the load capacitance for which the crystals frequenc y is specified. any mismatch in the load capacitance with respect to the crystals specification will lead to inaccurate oscillation frequency. ? crystal drive level use only crystals with the specified drive levels greater than the specified mcu oscillator drive level. applications that do not respect this criterion may damage the crystal. ? crystal equivalent series resistor (esr) use only crystals with the specified esr lower than the s pecified mcu oscillator esr. in applications where this criterion is not respected, the crystal oscillator may not start. ? crystal shunt capacitance use only crystal with the specified shunt capacitance lower than the specified mcu oscillator shunt capacitance. in applications where this criterion is not respected, the crystal oscillator may not start. ? pcb layout considerations to minimize inductive and capacitive parasitics associated with xin, xout, xin32, xout32, clkea, clkeb nets, it is recommended to route them as short as possible. it is also of prime importance to keep those nets away from noisy switching signals (clock, data, pwm, etc...). a good practice is to shield them with a quiet ground net to avoid coupling to neighbour signals.
1031 sam4cp [datasheet] 43051e?atpl?08/14 45.5.11 plla, pllb characteristics table 45-29. plla characteristics symbol parameter conditions min typ max unit v vddpll supply voltage range (vddpll) 1.08 1.2 1.32 v f in input frequency range 30 32.768 34 khz f out output frequency range 7.5 8.192 8.5 mhz n ratio frequency multiplying ratio (mula +1) ? 250 ? ? jp period jitter peak value ? 4 ? ns t on startup time from off to output oscillations (output frequency within 10% of target frequency) ? ? 250 s t lock lock time from off to pll locked ? ? 2.5 ms i pllon active mode current consumption (vddpll) f out = 8.192 mhz ? 50 ? a i plloff off mode current consumption (vddpll) @25c over the temperature range ? 0.05 0.05 0.30 5 a table 45-30. pllb characteristics symbol parameter conditions min typ max unit v vddpll supply voltage range (vddpll) 1.08 1.2 1.32 v f in input frequency range 3 ? 32 mhz f out output frequency range 80 ? 240 mhz n ratio frequency multiplying ratio (mulb +1) 3 ? 62 ? q ratio frequency dividing ratio (divb) 2 ? 24 ? t on startup time ? 60 150 s i vddpll current consumption on vddpll active mode @ 80 mhz @1.2v active mode @ 96 mhz @1.2v active mode @ 160 mhz @1.2v active mode @ 240 mhz @1.2v ? 0.94 1.2 2.1 3.34 1.2 1.5 2.5 4 ma
1032 sam4cp [datasheet] 43051e?atpl?08/14 45.5.12 temperature sensor the temperature sensor provides an output voltage (v t ) that is proportional to absolute temperature (ptat). this voltage can be measured through the channel number 7 of the 10-bit adc. improvement of the raw performance of the temperature sensor acquisition can be achieved by performing a single temperature point calibration to remove the initial inaccuracies (v t and adc offsets). notes: 1. does not include errors due to a/d conversion process. 45.5.13 optical uart rx transceiver characteristics table 45-32 gives the description of the optical link transceiver for electrically isolated serial communication with hand-held equipment, such as calibrators compliant with ansi-c12.18 or iec62056-21 norms (only available on uart1). table 45-31. temperature sensor characteristics symbol parameter conditions min typ max unit v vddin supply voltage range (vddin) 2.5 ? 3.6 v v t output voltage t j = 27 c 1.34 1.44 1.54 v dv t / dt output voltage sensitivity to temperature 4.2 4.7 5.2 mv/c dv t / dv v t variation with vddin vddin from 2.5v to 3.6v ? ? 1 mv/v t s v t settling time when v t is sampled by the 10-bit adc, the required track-and-hold time to ensure 1oc accurate settling ?? 1 s t acc temperature accuracy (1) after offset calibration over t j range [-40c : +85c] ?5? c after offset calibration over t j range [0c : +80c] ?4? c t on startup time ? 5 10 s i vddin current consumption 50 70 80 a table 45-32. transceiver characteristics symbol parameter conditions min typ max unit v vddio supply voltage range (vddio) 3 3.3 3.6 v i dd current consumption on off ? 25 ? 35 0.1 a v th comparator threshold according to the programmed threshold. see the opt_cmpth bit in the uart mode register (uart1) -20 ? +20 mv v hyst hysteresis 10 20 40 mv t prop propagation time with 100 mvpp square wave input around threshold ?? 5 s t on startup time ? ? 100 s
1033 sam4cp [datasheet] 43051e?atpl?08/14 45.5.14 10-bit adc characteristics note: 1. average current consumption performing conversion in free run mode @ 16 mhz adc clock. f s = 510 ks/s. note: 1. advref input range limited to vddio if vddio < vddin. notes: 1. t conv = (tracktim + 24) / f ck_adc. 2. f s = 1 / t conv. 3. refer to section 45.5.14.1 ?track and hold time versus source output impedance, effective sampling rate? . table 45-33. adc power supply characteristics symbol parameter conditions min typ max unit v vddin supply voltage range (vddin) 2.5 3.3 3.6 v i vddin current consumption on vddin adc on (1) , internal voltage reference on generating advref = 3.0v ? 450 700 a adc on (1) , internal voltage reference off, advref externally supplied ? 220 350 table 45-34. adc voltage reference input characteristics (advref pin) symbol parameter conditions min typ max unit v advref advref input voltage range (1) internal voltage reference off 2.4 ? v vddin v r advref advref input resistance adc on, internal voltage reference off 9 14 19 k i advref current consumption on advref advref = 2.4v -35% 170 +35% a advref = 3.3v 235 advref = 3.6v 260 c advref decoupling capacitor on advref 100 ? ? nf table 45-35. adc timing characteristics symbol parameter conditions min typ max unit f ck_adc adc clock frequency 3.0v ? vddin ? 3.6v 2.5v ? vddin ? 3.0v ?? 16 14 mhz t conv adc conversion time (1) f ck_adc = 16 mhz, t track = 500 ns 1.95 ? ? s f s sampling rate (2) v vddin > 3.0v, f ck_adc = 16 mhz v vddin > 2.5v, f ck_adc = 14 mhz ?? 510 380 ks/s t on startup time adc only ? ? 40 s t track track and hold time (3) 2.5v ? vddin ? 3.0v 3.0v < vddin < 3.6v 1000 500 ?? ns
1034 sam4cp [datasheet] 43051e?atpl?08/14 notes: 1. if v vddio < v advref , full scale range is limited to vddio. 2. see figure 45-13 ?simplified acquisition path? . notes: 1. in this table, values expressed in lsb refer to the native adc resolution (i.e. a 10-bit lsb). table 45-36. adc analog input characteristics symbol parameter conditions min typ max unit fsr analog input full scale (1) range 0 ? v advref v c in input capacitance (2) accounts for i/o input capacitance + adc sampling capacitor ? ? 10 pf table 45-37. static performance characteristics (1) symbol parameter conditions min typ max unit r adc native adc resolution ? 10 ? bits r adc_av resolution with digital averaging see ?adc controller? section 10 ? 12 bits inl integral non linearity f ck_adc = 16 mhz errors with respect to the best fit line method -2 ? +2 lsb dnl differential non linearity -1 ? +1 lsb oe offset error -5 ? 5 lsb ge gain error -3 ? +3 lsb table 45-38. dynamic performance characteristics symbol parameter conditions min typ max unit snr signal to noise ratio f ck_adc = 16 mhz v advref = v vddin f in = 50 khz v inpp = 0.95 x v advref 57 60 ? db thd total harmonic distortion ? -68 -55 db sinad signal to noise and distortion 52 59 ? db enob effective number of bits 8.3 9.6 ? bits
1035 sam4cp [datasheet] 43051e?atpl?08/14 45.5.14.1 track and hold time versus source output impedance, effective sampling rate the following figure gives a simplified view of the acquisition path. figure 45-13. simplified acquisition path during its tracking phase, the 10-bit adc charges its samp ling capacitor through various serial resistors: source output resistor, multiplexer series resistor and the sampling switch series resistor. in case of high output source resistance (low power resistive divider, for example), the track time must be increased to ensure full settling of the sampling capacitor voltage. the following formulas give the minimum track time that guarantees a 10-bit accurate settling: ? v vddin > 3.0v: t track (ns) = 0.12 x r source ( )+ 500. ? v vddin ? 3.0v: t track (ns) = 0.12 x r source ( )+ 1000. according to the calculated track time (t track ), the actual track time of the adc must be adjusted through the tracktim field in the adc_mr register. tracktim is obtained by the following formula: tracktim = floor (t track / t ck_adc ) with t ck_adc = 1 / f ck_adc and floor (x) the mathematical function that rounds x to the greatest previous integer. the actual conversion time of the converter is obtained by the following formula: t conv = (tracktim + 24) x t ck_adc when converting in free run mode, the actual sampling rate of the converter is (1/ t conv ) or as defined by the following formula: f s = f ck_adc / (tracktim + 24) track & hold mux. zsource ron csample adc input cpad 10-bit adc core vddio sam4cp
1036 sam4cp [datasheet] 43051e?atpl?08/14 the maximum source resistance with the actual tracktim setting is: ? r source_max ( ) = ((tracktim + 1) x t ck_adc (ns ) - 500) / 0.12 for v vddin > 3.0v; or ? r source_max ( ) = ((tracktim + 1) x t ck_adc (ns ) - 1000) / 0.12 for v vddin ? 3.0v. example: calculated track time is lower than actual adc clock period ? assuming: f ck_adc = 1 mhz (t ck_adc = 1 s), r source = 100 and v vddin = 3.3v. ? the minimum required track time is: t track = 0.12 x 100 + 500 = 512 ns. ? t track begin less than t ck_adc , tracktim is set to 0. actual track time is t ck_adc = 1 s. ? the calculated sampling rate is: f s = 1 mhz / 24 = 41.7 khz. ? the maximum allowable source resistance is: r source_max = (1000 - 500) / 0.12 = 4.1 k . example: calculated track time is greater than actual adc clock period ? assuming: f ck_adc = 16 mhz (t ck_adc = 62.5 ns), r source = 600 and v vddin = 2.8v. ? the minimum required track time is: t track = 0.12 x 600 + 1000 = 1072 ns. ? tracktim = floor (1072/62.5) = 17. actual track time is: (17 + 1) x t ck_adc = 1.125 s. ? the calculated sampling rate is: f s = 16 mhz / (24 + 17) = 390.2 khz. ? the maximum allowable source resistance is: r source_max = (1125 - 1000) / 0.12 = 1.04 k .
1037 sam4cp [datasheet] 43051e?atpl?08/14 45.5.15 programmable voltage reference characteristics sam4cp embeds a programmable voltage reference designed to drive the 10-bit adc advref input. table 45-39 shows the electrical characteristics of this internal voltage reference. in case of need, this voltage reference can be bypassed with some level of configurability: the user can either choose to feed the advref input with an external voltage source or with the vddio internal power rail. see programming details in the adc analog control register (adc_acr) in the adc controller section. notes: 1. t c = (max (v advref ) - min (v advref )) / ((t max - t min ) * v advref (25oc)). 2. does not include the current consumed by the adcs advref input if adc is on. notes: 1. voltage reference values are configurable in the adc_acr register (the irvs field). table 45-39. programmable voltage reference characteristics symbol parameter conditions min typ max unit v vddin voltage reference supply range ? 2.5 ? 3.6 v v advref programmable output range see table 45-40 v vddin > v advref + 100mv 1.6 ? 3.4 v acc reference voltage accuracy with respect to the programmed value v vddin = 3.3v; t j = 25oc -3 ? 3 % t c temperature coefficient box method (1) ? ? 250 ppm/oc t on startup time v vddin = 2.5v v vddin = 3.0v v vddin = 3.6v ?? 100 70 40 s z load load impedance resistive 4 ? ? k capacitive 0.1 ? 1 f i vddin current consumption on vddin (2) adc is off ? 20 30 a table 45-40. programmable voltage reference selection values sel. value (1) advref notes 0 2.40 default value 1 2.28 ? 2 2.16 ? 3 2.04 ? 4 1.92 ? 5 1.80 ? 6 1.68 ? 7 1.55 min value 8 3.38 max value 9 3.25 ? a 3.13 ? b 3.01 ? c 2.89 ? d 2.77 ? e 2.65 ? f 2.53 ?
1038 sam4cp [datasheet] 43051e?atpl?08/14 45.6 embedded flash characteristics 45.6.1 embedded flash dc characteristics 45.6.2 embedded flash ac characteristics 45.6.2.1 flash wait states and operating frequency the maximum operating frequency given in table 45-43 below is limited by the embedded flash access time when the processor is fetching code out of it. the table give the device maximum operating frequency depending on the fws field of the efc_fmr register. this field defines the number of wait states required to access the embedded flash memory. table 45-41. dc flash characteristics symbol parameter conditions typ max unit i cc active current random 128-bit read: maximum read frequency onto vddcore = 1.2v @ 25c maximum read frequency onto vddio = 3.3v @ 25c 16 3 25 5 ma random 64-bit read: maximum read frequency onto vddcore = 1.2v @ 25c maximum read frequency onto vddio = 3.3v @ 25c 10 3 18 5 program: - onto vddcore = 1.2v @ 25c - onto vddio = 3.3v @ 25c 3 10 5 15 ma erase: - onto vddcore = 1.2v @ 25c - onto vddio = 3.3v @ 25c 3 10 5 15 ma table 45-42. ac flash characteristics parameter conditions min typ max unit program/ erase operation cycle time write page (512bytes) ? 1.5 3 ms erase page ? 10 50 ms erase block (4 kbytes) ? 50 200 ms erase sector ? 400 950 ms full chip erase (1 mbyte) ? 9 18 s lock/unlock time per region ? 1.5 3 ms data retention not powered or powered ? 20 ? years endurance write/erase cycles per page, block or sector @ 85c 10k ? ? cycles table 45-43. flash wait state versus operating frequency fws (flash wait state) maximum operating frequency (mhz) @ t = 85c vddcore = 1.08v vddio = 3.0v to 3.6v vddcore = 1.2v vddio = 3.0v to 3.6v 016 17 133 35 251 52 367 70 485 87 5 100 105 6 ? 121
1039 sam4cp [datasheet] 43051e?atpl?08/14 45.7 power supply current consumption this section provides information about the current consumption on different power supply rails of the device. it gives current consumption in low-power modes (backup mode, wait mode, sleep mode) and in active mode (the application running from memory, by peripheral). all the consumption values in sections 45.7.1 to 45.7.4 are measured with plc transceiver disabled (see table 45-54 in section 45.7.5 for plc consumption values). 45.7.1 backup mode current consumption the backup mode configuration and measurements are defined as follows. the configuration a is to achieve the lowest possible current consumption in this mode, the configurations b, c and d are typical use cases with crystal oscillator, lcd and anti-tampering enabled. reminder: in backup mode, the core voltage regulator is off and thus all the digital logics powered by vddcore is off. the backup mode is a low-power mode with the lowest possible expenses of the start-up time. 45.7.1.1 backup mode configuration a: embedded slow clock rc oscillator enabled ? por backup on vddbu is disabled. ? rtc running. ? rtt enabled on 1 hz mode. ? force wake-up (fwup) enabled. ? plc in shutdown. ? current measurement as per figure 45-14 on page 1039 . 45.7.1.2 backup mode configuration b: 32.768 khz crystal oscillator enabled ? por backup on vddbu is disabled. ? rtc running. ? rtt enabled on 1 hz mode. ? force wake-up (fwup) enabled. ? anti-tamper input tmp0 enabled. ? plc in shutdown. ? current measurement as per figure 45-14 on page 1039 . figure 45-14. measurement setup for configurations a and b amp1 vddin vddout vddcore 1.6v to 3.6v vddbu sam4cp vddpll vddlcd vddio
1040 sam4cp [datasheet] 43051e?atpl?08/14 45.7.1.3 backup mode configuration c: 32.768 khz crystal oscillator enabled ? por backup on vddbu is disabled. ? rtc running. ? rtt enabled on 1 hz mode. ? force wake-up (fwup) enabled. ? anti-tamper input tmp0, tmp1, tmp2, tmp3 and rtcout0 enabled. ? main crystal oscillator disabled. ? system io lines pa30, pa31, pb[0...3] in gpio input pull-up mode. ? plc in shutdown. ? all other gpio lines in default state (see pio multiplexing table). ? current measurement as per figure 45-15 on page 1041 . 45.7.1.4 backup mode configuration d: 32.768 khz crystal oscillator and lcd enabled ? por backup on vddbu is disabled. ? rtc running. ? rtt enabled on 1 hz mode. ? lcd controller in low-power mode, static bias and x64 slow clock buffer on-time drive time. ? lcd voltage regulator used. ? force wake-up (fwup) enabled. ? anti-tamper input tmp0, tmp1, tmp2, tmp3 and rtcout0 enabled. ? main crystal oscillator disabled. ? system io lines pa30, pa31, pb[0...3] in gpio input pull-up mode. ? plc in shutdown. ? all other gpio lines in default state (see pio multiplexing table). ? current measurement as per figure 45-15 on page 1041 . table 45-44. typical current consumption values for backup mode configurations a and b conditions configuration a configuration b unit vddbu = 3.6v @25c vddbu = 3.3v @25c vddbu = 3.0v @25c vddbu = 2.5v @25c vddbu = 1.6v @25c 580 520 480 440 400 760 700 680 640 600 na vddbu = 3.6v @85c vddbu = 3.3v @85c vddbu = 3.0v @85c vddbu = 2.5v @85c vddbu = 1.6v @85c 1.57 1.5 1.44 1.3 1.16 1.8 1.7 1.65 1.56 1.43 a
1041 sam4cp [datasheet] 43051e?atpl?08/14 figure 45-15. measurement setup for configurations c and d note: no current is drawn on vddin power input in backup mode. the pin vddin can be left unpowered in backup mode. 45.7.2 wait mode current consumption wait mode configuration and measurements are defined in section 45.7.2.1 ?wait mode configuration? . reminder: in wait mode, the core voltage regulator is on, but the device is not clocked. flash power mode can be either in stand-by mode or deep power-down mode. wait mode provides a much faster wake-up compared to backup mode. 45.7.2.1 wait mode configuration ? 32.768 khz crystal oscillator running. ? fast rc oscillator, main crystal and plls stopped. ? rtc running. ? rtt enabled on 1 hz mode. ? core bod enabled. ? one wake-up pin (wkupx) used in fast wake-up mode. ? anti-tamper input tmp0, tmp1, tmp2, tmp3 and rtcout0 enabled. ? system io lines pa30, pa31, pb[0...3] in gpio input pull-up mode. ? plc in shutdown. ? all other gpio lines in default state. table 45-45. typical current consumption values for backup mode configurations c and d conditions configuration c configuration d unit idd_bu - amp1 idd_in/io - amp2 idd_bu - amp1 idd_in/io - amp2 vddio = 3.6v @25c vddio = 3.3v @25c vddio = 3.0v @25c 0.05 2.6 2.4 2.1 0.05 9.5 9.0 8.5 a vddio = 3.6v @85c vddio = 3.3v @85c vddio = 3.0v @85c 0.09 6.7 6.2 5.8 0.1 14.8 14.0 13.5 amp1 vddin vddout vddcore 3v amp2 2.5v to 3.6v vddbu sam4cp vddpll rtcout0 tmp[0...3] vddlcd vddio comx segx
1042 sam4cp [datasheet] 43051e?atpl?08/14 ? current measurement as per figure 45-16 . figure 45-16. measurement setup for wait mode configuration 45.7.3 sleep mode current consumption sleep mode configuration and measurements are defined further on in this section. reminder: the purpose of sleep mode is to optimize power consumption of the device versus response time. in this mode, only the core clock of cm4p0 and/or cm4p1 are stopped. figure 45-17. measurement setup for sleep mode table 45-46. typical current consumption in wait mode conditions idd_bu - amp1 idd_in/io - amp2 idd_core - amp3 unit @25c @85c @25c @85c @25c @85c flash in read-idle mode 0.003 0.09 68 476 45 446 a flash in standby mode 0.003 0.09 66 474 45 446 flash in deep power down mode 0.003 0.09 62 469 45 446 amp1 vddin vddout vddcore 3v amp2 amp3 3.3v vddbu sam4cp vddpll vddlcd vddio amp1 vddin vddout vddcore 3.3v amp2 vddbu sam4cp vddpll vddlcd vddio amp3
1043 sam4cp [datasheet] 43051e?atpl?08/14 ? vddio = vddin = 3.3v. ? vddcore = 1.2v (internal voltage regulator used). ? t a = 25c. ? core 0 clock (hclk) and core 1 (cphclk) clock stopped. ? sub-system 0 master clock (mck), sub-system 1 master clock (cpbmck) running at various frequencies (pllb used for frequencies above 12 mhz, fast rc oscillator at 12 mhz for the 12 mhz point, and fast rc oscillator at 8 mhz divided by 1/2/4/8/16/32 for lower frequencies). ? all peripheral clocks deactivated. ? no activity on i/o lines. ? plc in shutdown. ? vddpll not taken into account. see pll characteristics for further details. ? current measurement as per figure 45-17 . 45.7.4 active mode power consumption the current consumption configuration for active mode, i.e., core executing codes, are as follow: ? vddio = vddin = 3.3v. ? vddcore = 1.2v (internal voltage regulator used). ? t a = 25c. ? sub-system 0 master clock (mck) and core clock (hclk), sub-system 1 master clock (cpbmck) and core clock (cphclk) running at various frequencies (pllb used for frequencies above 8 mhz and fast rc oscillator at 8 mhz divided by 1/2/4/8/16/32 for lower frequencies). ? all peripheral clocks are deactivated. ? no activity on i/o lines. ? plc in shutdown. ? flash wait state (fws) in eefc_fmr adjusted versus core frequency. ? current measurement as per figure 45-18 . table 45-47. typical sleep mode current consumption versus frequency master clock (mhz) idd_in - amp1 idd_io - amp2 idd_core - amp3 unit 120 14.26 0.03 10.83 ma 100 11.96 0.03 9.09 84 10.1 0.03 7.68 64 7.78 0.03 5.92 48 5.93 0.03 4.48 32 5.02 0.03 3.16 24 3.85 0.03 2.4 12 1.26 0.03 1.21 8 0.88 0.03 0.83 4 0.5 0.03 0.45 2 0.32 0.03 0.27 1 0.26 0.03 0.22 0.5 0.22 0.03 0.2 0.25 0.19 0.03 0.18
1044 sam4cp [datasheet] 43051e?atpl?08/14 figure 45-18. measurement setup for active mode 45.7.4.1 test setup 1: coremark ? ? coremark on core 0 (cm4p0) running out of flash in 128-bit or 64-bit access mode with and without cache enabled. cache is enabled above 0 ws. ? sub-system 1 master clock (cpbmck) and core clock (cphclk) stopped and in reset state. amp1 vddin vddout vddcore 3.3v amp2 vddbu sam4cp vddpll vddlcd vddio amp3 table 45-48. test setup 1 current consumption 128-bit flash access 64-bit flash access unit clock (mhz) cache enabled cache disabled cache enabled cache disabled ma idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 26 0.3 23 29 2 26 26 0.27 23 26 1.9 22 100 22 0.3 19 25 1.8 22.5 22 0.27 19 21 1.75 18.4 84 19 0.3 17 22 1.7 19 19 0.27 17 19.5 1.65 16.2 64 15 0.3 12 16 1.5 14 15 0.27 12 14 1.44 13.4 48 11.5 0.3 9.85 13.5 1.4 12 11.5 0.27 9.85 12 1.32 12 32 9.5 0.3 7.5 10 1.2 8.5 9.5 0.27 7.5 9 1.2 8 24 5.6 0.3 4.35 7.7 1.1 6.7 5.6 0.27 4.35 7 1.17 6 12 2.4 0.05 2.3 3.2 0.9 3 2.4 0.09 2.3 3.1 1 3.1 8 1.65 0.05 1.61 2.1 0.7 2 1.65 0.09 1.61 2.1 0.9 2.1 4 1 0.05 1 1.4 0.5 1.36 1 0.09 1 1.36 0.8 1.4 2 0.7 0.05 0.68 0.9 0.4 0.9 0.7 0.09 0.68 0.7 0.7 0.7 1 0.55 0.05 0.53 0.65 0.3 0.65 0.55 0.09 0.53 0.65 0.4 0.65 0.5 0.47 0.05 0.45 0.5 0.2 0.5 0.47 0.09 0.45 0.6 0.2 0.6 0.25 0.25 0.05 0.24 0.26 0.1 0.25 0.25 0.09 0.24 0.36 0.1 0.25
1045 sam4cp [datasheet] 43051e?atpl?08/14 45.7.4.2 test setup 2: coremark ? coremark on core 1 (cm4p1) running out of sram1 (code) / sram2 (data). ? core 0 (cm4p0) in sleep mode. 45.7.4.3 test setup 3: coremark ? coremark on core 0 (cm4p0) running out of flash in 128-bit or 64-bit access mode with and without cache enabled. cache is enabled above 0 ws. ? coremark on core 1 (cm4p1) running out of sram1 (code) / sram2 (data). table 45-49. test setup 2 current consumption clock (mhz) sram1, sram2 unit idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 22.3 0.05 19 ma 100 19 0.05 16 84 16 0.05 13.83 64 12.2 0.05 10.66 48 9.2 0.05 7.9 32 7.15 0.05 5.5 24 5.4 0.05 4.15 12 2.1 0.05 2 8 1.5 0.05 1.4 4 0.8 0.05 0.75 2 0.5 0.05 0.45 1 0.32 0.05 0.38 0.5 0.21 0.05 0.2 0.25 0.13 0.05 0.12 table 45-50. test setup 3 current consumption 128-bit flash access 64-bit flash access unit clock (mhz) cache enabled cache disabled cache enabled cache disabled ma idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 32.5 0.28 29 35 2 30 31.2 0.28 28 30.8 1.8 27.4 100 32.3 0.28 27.8 29.8 1.75 27 26.4 0.28 23.6 27 1.7 24.3 84 28.5 0.28 23.8 26.3 1.68 24 22.3 0.28 20 24 1.7 21.8 64 23.5 0.28 18.6 20.9 1.5 19.3 17.2 0.28 15.6 19.7 1.6 18 48 18.3 0.28 14.4 16.5 1.4 15.3 13 0.28 11.8 16 1.5 14.7 32 14.2 0.28 10.8 12.6 1.2 10.9 9.8 0.28 8.15 12.5 1.4 10.6 24 12 0.28 8.3 9.5 1.1 8.25 7.4 0.28 6.2 9.4 1.2 8.2 12 6.1 0.1 3.6 4.2 0.9 4 3.1 0.1 3.1 4.2 1.1 4.2 8 2.1 0.1 2 2.85 0.8 2.8 2.1 0.1 2.1 2.8 1 2.7 4 1.1 0.1 1 1.5 0.6 1.45 1.2 0.1 1.2 1.5 0.9 1.4 2 0.65 0.1 0.61 0.82 0.4 0.8 0.65 0.1 0.6 0.8 0.66 0.75 1 0.38 0.1 0.35 0.47 0.25 0.45 0.38 0.1 0.37 0.47 0.38 0.4 0.5 0.25 0.1 0.24 0.3 0.18 0.28 0.25 0.1 0.23 0.3 0.25 0.28 0.25 0.14 0.1 0.13 0.16 0.1 0.14 0.15 0.1 0.12 0.16 0.15 0.13
1046 sam4cp [datasheet] 43051e?atpl?08/14 45.7.4.4 test setup 4: dsp application from arm cmsis dsp library ? application running on core 1 (cm4p1) out of sram1 (code) / sram2 (data). ? core 0 (cm4p0) in sleep mode. 45.7.4.5 test setup 5: dsp application from arm cmsis dsp library ? application running on core 0 (cm4p0) out of flash in 128-bit or 64-bit access mode with and without cache enabled. cache is enabled above 0 ws. ? sub-system 1 master clock (cpbmck) and core clock (cphclk) stopped and in reset. ? vddio = vddin = 3v. table 45-51. test setup 4 current consumption clock (mhz) dsp application unit idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 22.8 0.05 19.4 ma 100 19.2 0.05 17 84 16.25 0.05 13.83 64 12.53 0.05 10.66 48 9.53 0.05 8.08 32 7.44 0.05 5.59 24 5.68 0.05 4.23 12 2.17 0.05 2.13 8 1.48 0.05 1.45 4 0.8 0.05 0.76 2 0.47 0.05 0.43 1 0.3 0.05 0.27 0.5 0.25 0.05 0.22 0.25 0.18 0.05 0.16 table 45-52. test setup 5 current consumption 128-bit flash access unit clock (mhz) cache enabled cache disabled ma idd_in (amp1) idd_i0 (amp2) idd_core (amp3) idd_in (amp1) idd_i0 (amp2) idd_core (amp3) 120 24 0.31 22 26.5 2.1 23 100 21 0.31 19 23.7 2 21 84 18 0.31 16 21.2 1.9 19 64 16 0.31 14 17.2 1.8 15.5 48 13 0.31 9 14 1.6 12.7 32 9 0.31 6 10.6 1.4 9 24 6 0.31 4.5 8.7 1.2 7.45 12 3 0.05 2.6 4 0.82 3.8 8 1.8 0.05 1.77 2.6 1.25 2.5 4 1 0.05 0.9 1.5 0.9 1.4 2 0.56 0.05 0.54 0.85 0.5 0.75 1 0.38 0.05 0.37 0.475 0.27 0.47 0.5 0.27 0.05 0.25 0.375 0.15 0.32 0.25 0.22 0.05 0.2 0.275 0.1 0.24
1047 sam4cp [datasheet] 43051e?atpl?08/14 45.7.5 peripheral power consumption in active mode notes: 1. v vddio = 3.3v, v vddcore = 1.2v, t a = 25c. table 45-53. power consumption on v vddcore (1) peripheral consumption (typical) unit pio controller 4.0 a / mhz uart0 5.4 uart1 5.4 usart[0 - 4] 7.7 pwm 3.9 twi 5.3 spi 5.0 timer counter (tcx) 2.7 adc 3.9 slcd 0.16 aes: performing aes256 encryption 164 trng 6.2 icm 5.2 table 45-54. plc power consumption parameter condition symbol rating unit min typ max power consumption t j = 25oc vddio = 3.3v vddin = 3.3v vddin an = 3.3v p 25 - 160 - mw power consumption (worst case) t j = 125oc vddio = 3.6v vddin = 3.6v vddin an = 3.6v p 125 - - 270
1048 sam4cp [datasheet] 43051e?atpl?08/14 45.8 power on considerations during power-on, pll init pin should be tied to ground during 4 s at least, in order to ensure proper system start up. after releasing pll init, the system will start no later than 612 s. after power-up system can be restarted by means of low active pulse (min 1.65 s) in arst or srst. system full operation starts after 410 s (arst pulse) or after 0.9 s (srst pulse). in case of simultaneous tie down of more than one initialization pin the longest time for operation must be respected. figure 45-19. pll init initialization diagram full operation pll init arst srst > 4us > 612us > 410us > 0.9us > 1.65us* > 1.65us* system (*) 1.65us = 33*tclk
1049 sam4cp [datasheet] 43051e?atpl?08/14 46. sam4cp mechanical characteristics figure 46-1. 176-lead lqfp package mechanical drawing
1050 sam4cp [datasheet] 43051e?atpl?08/14 this package respects the recommendations of the nemi user group. 46.1 soldering profile table 46-3 gives the recommended soldering profile from j-std-020c. note: the package is certified to be backward compatible with pb/sn soldering profile. a maximum of three reflow passes is allowed per component. 46.2 packaging resources this section provides land pattern definition. refer to the following ipc standards: ? ipc-7351a and ipc-782 ( generic requirements for surface mount design and land pattern standards ) http://landpatterns.ipc.org/default.asp ? atmel green and rohs policy and package material declaration data sheet http://www.atmel.com/about/quality/package.aspx table 46-1. lqfp package reference jedec drawing reference ms-026 table 46-2. lqfp package characteristics moisture sensitivity level 3 table 46-3. soldering profile profile feature green package average ramp-up rate (217c to peak) 3c/sec. max. preheat temperature 175c 25c 180 sec. max. temperature maintained above 217c 60 sec. to 150 sec. time within 5c of actual peak temperature 20 sec. to 40 sec. peak temperature range 260c ramp-down rate 6c/sec. max. time 25c to peak temperature 8 min. max.
1051 sam4cp [datasheet] 43051e?atpl?08/14 47. marking all devices are marked with the atmel logo and the ordering code. additional marking is as follows: where ? ?yy?: manufactory year ? ?ww?: manufactory week ? ?v?: revision ? ?xxxxxxxxx?: lot number yyww v xxxxxxxxx arm
1052 sam4cp [datasheet] 43051e?atpl?08/14 48. ordering information table 48-1. ordering codes for sam4cp devices ordering code mrl flash (kbytes) package package type temperature operating range atsam4cp16b-ahu-y a 1*1024 lqfp176 green industrial (-40c to +85c)
1053 sam4cp [datasheet] 43051e?atpl?08/14 49. errata 49.1 supply controller (supc) 49.1.1 supc: supply monitor (sm) on vddio the supply monitor (sm) sampling mode reducing the average current consumption on vddio is not functional. problem fix/workaround use the supply monitor in continuous mode only. 49.1.2 supc: core voltage regulator standby mode control the core voltage regulator standby mode controlled by the onreg bit in supc_mr is not functional. this does not prevent to power vddcore and vddpll by using an external voltage regulator. problem fix/workaround none. do not use the onreg bit. 49.1.3 supc: core brownout detector. unpredictable behavior if bod is disabled, vddcore is lost and vddio is powered in active mode or in wait mode, if the brownout detector (bod) is disabled (supc_mr: boddis=1) and power is lost on vddcore while vddio is powered, the device can be reset incorrectly and its behavior becomes then unpredictable. problem fix/workaround when the brownout detector is disabled in active or in wait mode, vddcore must be always powered. 49.2 parallel input output (pio) controller 49.2.1 pio: schmitt trigger ? schmitt triggers on all pio controllers are not enabled by default (after reset) as stated in the product datasheet. ? enable and disable values in the pio schmitt trigger register (for all pio controllers) are inverted. the definition of pio_schmitt fields must be as follows: ? 0: schmitt trigger is disabled. ? 1: schmitt trigger is enabled. problem fix/workaround none. it is up to the application to enable schmitt trigger mode and to take into account the inverted values of the pio_schmitt fields. 49.3 watchdog (wdt) / reinforced safety watchdog (rswdt) 49.3.1 wdt / rswdt not stopped in wait mode when the watchdog (wdt) or the reinforced safety watch dog (rswdt) is enabled an the waitmode bit set to 1 is used to enter low-power wait mode, the wdt/rswdt is not halted. if the time spent in wait mode is longer than the watchdog (reinforced safety watchdog) time-out, the device is reset provided that the wdt/rswdt reset is enabled.
1054 sam4cp [datasheet] 43051e?atpl?08/14 problem fix/workaround when entering wait mode, the wait-for-event (wfe) instruction of the cortex-m4 processor must be used while the sleepdeep bit of the cortex-m system control register (scb_scr) is set to 0. 49.4 enhanced embedded flash controller (eefc) 49.4.1 eefc: erase sector (es) command cannot be performed if a subsector is locked (only in flash sector 0) if one of the subsectors ? small sector 0 ? small sector 1 ? larger sector is locked within the flash sector 0, the erase sector (es) command cannot be processed on non-locked subsectors. refer to the flash overview in the ?memories? section of the datasheet. problem fix/workaround all the lock bits of the sector 0 must be cleared prior to issuing the es command. after the es command has been issued, the lock bits must be reverted to the state before clearing them. 49.5 wait for interrupt (wfi) 49.5.1 inter wait-for-interrupt (wfi) when entering sleep mode, if an interrupt occurs during wfi or wfe (pmc_fsmr.lpm=0) instruction processing, the arm core may read an incorrect data, thus leading to unpredictable behavior of the software. this issue is not present in wait mode. problem fix/workaround one of the following conditions must be satisfied to correct the issue: 1. the interrupt vector table must be located in flash and the number of wait state on the flash is > 0. 2. the interrupt vector table must be located in flash and the flash wait state = 0, then the matrix slave interface for the flash must be set to ?no default master?. this is done by setting the field defmstr_type to 0 in the register matrix_scfg. the code example below can be used to program the no_default_master state: matrix_scfg[2] = matrix_scfg_slot_cycle(0x1ff) | matrix_scfg_defmstr_type(0x0) this operation must be done once in the software before entering sleep mode. 49.6 power supply and power control / clock system 49.6.1 core 1 systick clock input (cpsystick) is fed by core 0 processor clock (hclk) if the core 0 processor clock (hclk) frequency is higher than 8 times the frequency of the core 1 processor clock (cphclk), the systick counter behavior is erratic. problem fix/workaround always ensure that f hclk < 8 x f cphclk
1055 sam4cp [datasheet] 43051e?atpl?08/14 49.7 power management controller (pmc) 49.7.1 srcb bit in ckgr_pllb register the srcb bit is programmed in bit 29 of the ckgr_pllb register but must be read in bit 27 of this register. problem fix/workaround for srcb, read bit 27 of the ckgr_pllb register.
1056 sam4cp [datasheet] 43051e?atpl?08/14 50. revision history in the table that follow, the most recent version of the document appears first. doc. rev. 43051 comments change request ref. e minor changes. ?sclk? replaced by ?slck? in all document. power supply and power control modified section 5.1.2 ?lcd voltage regulator? on page 14 . modified section 5.1.4 ?automatic power switch? on page 14 . modified section 5.1.5 ?typical powering schematics? on page 14 . added section 5.1.5.2 ?single supply with backup battery? on page 16 . modified section 5.1.5.3 ?single power supply using one main battery and lcd controller in backup mode? on page 17 . updated section 5.3.2 ?device configuration after a power cycle when booting from flash memory? on page 20 and section 5.3.3 ?device configuration after a reset? on page 20 . input/output lines updated section 6.9 ?erase pin? on page 28 . memories updated section 8.1.4.5 ?security bit feature? on page 35 . added section 8.1.5.4 ?sub-system 1 start-up time? on page 37 system controller updated section 10.2.4 ?supply monitor on vddio? on page 41 . peripherals table 11-4, ?i/o line features abbreviations? : removed medium drive. added maximum drive. table 11-5, ?multiplexing on pio controller a (pioa)? , table 11-6, ?multiplexing on pio controller b (piob)? , table 11-7, ?multiplexing on pio controller c (pioc)? : modified features column in all tables for all i/o lines. arm cortex-m4 processor corrected instruction in section 12.5.3 ?power management programming hints? on page 79 . updated table 12-5, ?memory region shareability policies? updated table 12-11, ?faults? updated table 12-31, ?mapping of interrupts to the interrupt variables? updated table 12-41, ?memory protection unit (mpu) register mapping? with new register names for mpu_rbar_ax and mpu_rasr_ax. section 12.9.1.13 ?configurable fault status register? on page 207 added lsperr bit. sam4cp boot program section 14.5.3 ?in application programming (iap) feature? on page 266 : corrected mc_fsr to eefc_fsr.
1057 sam4cp [datasheet] 43051e?atpl?08/14 e reset controller (rstc) changed ?vdd_reg_bu? by ?vddbu?. removed section ?brownout manager?. section 15.4.3.2 ?backup reset? on page 270 replaced ?core_backup_reset? with ?vddcore_nreset?. section 15.5.1 ?reset controller control register? on page 274 modified extrst description. section 15.5.2 ?reset controller status register? on page 275 modified bit descriptions. section 15.5.3 ?reset controller mode register? on page 276 modified erstl bit description. real-time timer (rtt) modified section 16.4 ?functional description? on page 279 . section 16.5.1 ?real-time timer mode register? on page 281 modified rtpres description. section 16.5.2 ?real-time timer alarm register? on page 282 modified almv description. real-time clock (rtc) section 17.5.7 ?rtc accurate clock calibration? on page 289 modified paragraph on calibration circuitry. section 17.6.2 ?rtc mode register? on page 293 modified descriptions of negppm, highppm and thigh bits. added section 17.6.17 ?rtc write protection mode register? on page 310 ? . reinforced safety watchdog timer (rswdt) added windowed watchdog in section 19.2 ?embedded characteristics? on page 318 and section 19.4 ?functional description? on page 319 . updated section 19.4 ?functional description? on page 319 . modified figure 19-2 . section 19.5.2 ?reinforced safety watchdog timer mode register? on page 322 added notes. clock generator figure 29-1 and figure 29-4 updated for clarity. added section 29.5.5 ?switching main clock between the main rc oscillator and fast crystal oscillator? on page 532 . power management controller (pmc) figure 30-1 updated for clarity. section 30.10 ?main processor fast startup? on page 538 updated for clarity. added section 30.11 ?main processor startup from embedded flash? on page 539 . section 30.13 ?main clock failure detector? on page 540 updated for clarity. section 30.15 ?programming sequence? on page 541 updated for clarity. section 30.18.8 ?pmc clock generator main clock frequency register? on page 556 updated mainf bit description. chip identifier (chipid) section 31.3.1 ?chip id register? on page 578 (nvpsiz: nonvolatile program memory size): changed information in row for value 8. doc. rev. 43051 comments change request ref.
1058 sam4cp [datasheet] 43051e?atpl?08/14 e parallel input/output controller (pio) ?pio clock? and ?pio controller clock? replaced by ?peripheral clock?. ?mck? replaced by ?peripheral clock?. updated figure 32-2 . section 32.5.1 ?pull-up and pull-down resistor control? on page 585 added information on setting pull-up and pull-down. section 32.5.3 ?peripheral a or b or c or d selection? on page 586 added information on products that do not have a, b, c and d peripherals. section 32.6.38 ?pio additional interrupt modes mask register? on page 633 updated bit description. serial peripheral interface (spi) ?mck? replaced by ?peripheral clock?. modified section 33.7.3 ?master mode operations? on page 650 . modified figure 33-1 , figure 33-3 and figure 33-4 . modified section 33.7.3 ?master mode operations? on page 650 . section 33.8.2 ?spi mode register? on page 661 modified dlybcs bit description. section 33.8.9 ?spi chip select register? on page 670 added register addresses. two-wire interface (twi) ?mck? replaced by ?peripheral clock?. table 34-1, ?atmel twi compatibility with i2c standard? clock synchronization added as supported feature. section 34.7.3.3 ?programming master mode? on page 679 added note after section. section 34.7.3.7 ?using the peripheral dma controller (pdc)? on page 683 modified ?data transmit with the pdc? and ?data receive with the pdc?. ?clock synchronization in write mode?: at end of last sentence, changed ?in read mode? to ?in write mode?. section 34.7.3.5 ?master receiver mode? on page 681 removed reference to clock stretching in the ?warning?. (clock stretching is a slave-only mechanism). figure 34-11 changed title and figure to remove references to clock stretching reference (slave-only mechanism). ?clock stretching sequence?: added section which refers only to twi_thr. ?clock synchronization/stretching?: changed the section name and updated. universal asynchronous receiver transmitter (uart) ?mck? replaced by ?peripheral clock?. doc. rev. 43051 comments change request ref.
1059 sam4cp [datasheet] 43051e?atpl?08/14 e universal synchronous asynchronous receiver transmitter (usart) ?mck? replaced by ?peripheral clock?. section 36.2 ?embedded characteristics? on page 738 added ?digital filter on receive line? bullet. updated figure 36-1 . updated information on rxidlev bit in section 36.6.3.2 ?manchester encoder? on page 746 and section 36.7.21 ?usart manchester configuration register? on page 796 . updated figure 36-36 . section 36.6.7.5 ?character transmission? on page 767 inack replaced by wrdbt. section 36.7.3 ?usart mode register? on page 774 updated usart_mode, usclks and filter field descriptions. section 36.7.4 ?usart mode register (spi_mode)? on page 777 added clko bit. updated endrx, endtx, txbufe, and rxbuff bit descriptions in ?usart interrupt enable register? , ?usart interrupt enable register (spi_mode)? , ?usart interrupt disable register? , ?usart interrupt disable register (spi_mode)? and ?usart channel status register? . updated rxrdy, txrdy, txempty, and ctsic bit descriptions in ?usart channel status register? . updated rxrdy, txrdy, and txempty bit descriptions in ?usart channel status register (spi_mode)? . section 36.7.18 ?usart fi di ratio register? on page 793 fi_di_ratio field now 11 bits wide. timer counter (tc) ?mck? replaced by ?peripheral clock?. added section 37.6.14.6 ?missing pulse detection and auto-correction? on page 820 section 37.7.14 ?tc block mode register? on page 841 removed filter bit (register bit 19 now reserved). added autoc bit and maxcmp field. section 37.7.18 ?tc qdec interrupt status register? on page 846 added mpe bit. segment liquid crystal display controller (slcdc) updated section 39.5.2 ?power management? on page 875 . revised section 39.6.7 ?disabling the slcdc? on page 881 (was ?disable sequence?). section 39.8.8 ?slcdc interrupt mask register? on page 897 modified access to read-only. analog-to-digital converter (adc) added table 40-2 and table 40-3 . advanced encryption standard (aes) section 41.5.2 ?aes mode register? on page 956 updated procdly bit description. updated figure 41-4 . updated section 41.4.5 ?galois counter mode (gcm)? on page 947 . section 41.5.3 ?aes interrupt enable register? on page 958 , section 41.5.4 ?aes interrupt disable register? on page 959 , section 41.5.5 ?aes interrupt mask register? on page 960 added tagrdy bit. doc. rev. 43051 comments change request ref.
1060 sam4cp [datasheet] 43051e?atpl?08/14 e integrity check monitor (icm) updated section 42.1 ?description? on page 973 . added table 42-1 . renamed figure 42-1 (was ?integrity check monitor integrated in the system?). section 42.5.1.2 ?icm region configuration structure member? on page 978 corrected configuration value descriptions for bits rhien, dmien, beien, wcien, ecien and suien. sam4cp electrical characteristics table 45-5, ?i/o dc characteristics? : modified column ?conditions? for all parameters. added notes at end of table. table 45-7, ?input characteristics? added mention of voltage reference to vddio in paragraph preceding table. updated table 45-8, ?spi timings? . modified min and max values in table 45-9, ?usart spi timings? . modified max values in table 45-15, ?lcd buffers characteristics? . table 45-18, ?vddio supply monitor? : added note (2). removed figure ?vddio supply monitor?. table 45-24, ?32.768 khz crystal oscillator characteristics? : added parameter c crystal . modified parameter c lext to c lext32k modified figure 45-11 and text below this figure. table 45-26, ?3 to 20 mhz crystal oscillator characteristics(1)? : added parameter c crystal . modified parameter c lext modified figure 45-12 and text below this figure. table 45-31, ?temperature sensor characteristics? : modified condition of parameter v t settling time. table 45-33, ?adc power supply characteristics? : modified values for supply voltage range (vddin). table 45-34, ?adc voltage reference input characteristics (advref pin)? : modified min value of v advref table 45-39, ?programmable voltage reference characteristics? : modified v advref section 45.7.3 ?sleep mode current consumption? on page 1042 : modified information on sub-system frequencies. marking added this chapter. errata added this chapter. doc. rev. 43051 comments change request ref.
1061 sam4cp [datasheet] 43051e?atpl?08/14 d minor changes. signal description clkout: ?20mhz external clock output? changed to ?10mhz external clock output? in section 3. ?signal description? on page 7 clkout: ?20mhz external clock output? changed to ?10mhz external clock output? in section 27.5 ?signal description? on page 423 . prime power line communications (pplc) removed the following registers: ?0xfd53, 0xfd54, 0xfd55, 0xfd56, 0xfd5f, 0xfd60, 0xfd61 and 0xfd62?. ?address: 0xfe62 - 0xfe67? changed to ?address: 0xfeba (msb) ? 0xfebb (lsb)? in section 27.7.3.1.2 ?crc32 errors counter register ? on page 437 . updated section 27.7.3.3.3 ?ber hard average error registers? on page 457 ?ber hard average error registers?. ?reset: 0x000000? changed to ?reset: 0x00000000? in section 27.8.3.3.9 ?accumulated header evm registers? on page 484 . ?reset: 0x000000? changed to ?reset: 0x00000000? in section 27.8.3.3.10 ?accumulated payload evm registers? on page 486 . ?reset: 0x00000000? changed to ?reset: 0x000124f8? in section 27.8.3.5.4 ?tx timeout registers ? on page 496 . ?reset: 0x0000? changed to ?reset: 0x1111? in section 27.8.3.5.7 ?tx result register ? on page 503 . sam4cp electrical characteristics table 45-1, ?absolute maximum ratings*? : removed junction temperature. table 45-18, ?vddio supply monitor? : modified min and max values for parameter acc. table 45-23, ?4/8/12 mhz rc oscillators characteristics? : modified conditions for acc4, acc8, acc12. modified max values for acc8 and acc12. figure 45-15 : added note below figure. table 45-45, ?typical current consumption values for backup mode configurations c and d? : modified ?conditions? column to vddio. table 45-50, ?test setup 3 current consumption? : modified values for 128-bit flash access, cache enabled columns. removed section 45.5.14.2 ?10-bit adc with averager?. removed section 45.7.6 ?low-power mode wake-up time?. sam4cp mechanical characteristics table 46-1, ?lqfp package reference? and table 46-2, ?lqfp package characteristics? added. c ?rtcout? changed to ?rtcout0? in whole document. ?pkcc? changed to ?cpkcc? in whole document. ?adc_sr changed to ?adc_isr? in figure 40-3 and figure 40-4 . sam4cp electrical characteristics chapter updated. b changes in the terminology. a first issue. doc. rev. 43051 comments change request ref.
sam4cp [datasheet] 43051e?atpl?08/14 1062 table of contents description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1. features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.1 configuration summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.2 sam4cp application block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 2. block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3. signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4. package and pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.1 sam4cp package and pinout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5. power supply and power control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.1 power supplies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2 clock system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 5.3 system state at power-up. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.4 active mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 5.5 low-power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5.6 wake-up sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.7 fast start-up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 6. input/output lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 6.1 general purpose i/o lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 6.2 system i/o lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 6.3 test pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.4 nrst pin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.5 tmpx pins: anti-tamper pins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.6 rtcout0 pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 6.7 shutdown (shdn) pin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 8 6.8 force wake-up (fwup) pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 6.9 erase pin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 7. product mapping and peripheral access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 8. memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 8.1 embedded memories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9. real-time event management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 9.1 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 9.2 real-time event mapping list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 10. system controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 10.1 system controller and peripheral mapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 10.2 power supply monitoring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 10.3 reset controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 10.4 supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 11. peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 11.1 peripheral identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 11.2 peripheral dma controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 11.3 apb/ahb bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 11.4 peripheral signal multiplexing on i/o lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 12. arm cortex-m4 processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 12.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 12.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 12.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 12.4 cortex-m4 models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
1063 sam4cp [datasheet] 43051e?atpl?08/14 12.5 power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 12.6 cortex-m4 instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 12.7 cortex-m4 core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 12.8 nested vectored interrupt controller (nvic). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 12.9 system control block (scb) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 12.10 system timer (systick) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 15 12.11 memory protection unit (mpu) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 12.12 floating point unit (fpu). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 12.13 glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 13. debug and test features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 13.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 13.2 associated documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 13.3 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254 13.4 cross triggering debut events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 13.5 application examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 13.6 debug and test pin description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257 13.7 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 14. sam4cp boot program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 14.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 14.2 hardware and software constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 14.3 flow diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 14.4 device initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 14.5 sam-ba monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 15. reset controller (rstc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 15.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 15.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 15.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 15.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 15.5 reset controller (rstc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 16. real-time timer (rtt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 16.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 16.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 16.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 16.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 16.5 real-time timer (rtt) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 17. real-time clock (rtc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 17.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 17.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 17.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 17.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 6 17.5 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 17.6 real-time clock (rtc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 18. watchdog timer (wdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 18.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 18.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 18.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 18.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 18.5 watchdog timer (wdt) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313 19. reinforced safety watchdog timer (rswdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 19.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 19.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318 19.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
sam4cp [datasheet] 43051e?atpl?08/14 1064 19.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 19.5 reinforced safety watchdog timer (rswdt) user interface . . . . . . . . . . . . . . . . . . . . 320 20. supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 20.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 20.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 20.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 20.4 supply controller functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 20.5 register write protection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 20.6 supply controller (supc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 21. general-purpose backup registers (gpbr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 21.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 21.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 21.3 general purpose backup registers (gpbr) user interface . . . . . . . . . . . . . . . . . . . . . . 348 22. enhanced embedded flash controller (eefc) . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 22.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 22.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 22.3 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 0 22.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351 22.5 enhanced embedded flash controller (eefc) user interface . . . . . . . . . . . . . . . . . . . . 364 23. fast flash programming interface (ffpi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 23.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 23.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 23.3 parallel fast flash programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 24. cortex m cache controller (cmcc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 24.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 24.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 24.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 24.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380 24.5 cortex m cache controller (cmcc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381 25. interprocessor communication (ipc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 25.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 25.2 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 25.3 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 3 25.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 25.5 inter-processor communication (ipc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 394 26. bus matrix (matrix) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 26.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 26.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402 26.3 special bus granting mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 26.4 no default master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 26.5 last access master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 26.6 fixed default master . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 26.7 arbitration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 26.8 register write protection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 26.9 ahb bus matrix (matrix) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410 27. prime power line communications (pplc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 27.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 27.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419 27.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420 27.4 plc coupling circuitry description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 27.5 signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423
1065 sam4cp [datasheet] 43051e?atpl?08/14 27.6 peripheral registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424 27.7 mac coprocessor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 27.8 prime phy layer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462 28. peripheral dma controller (pdc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513 28.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513 28.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513 28.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514 28.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514 28.5 peripheral dma controller (pdc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516 29. clock generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 29.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 29.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527 29.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 29.4 slow clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528 29.5 main clock. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530 29.6 divider and pll blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 33 30. power management controller (pmc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 30.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 30.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535 30.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536 30.4 master clock controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 30.5 processor clock controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 7 30.6 systick clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 537 30.7 peripheral clock controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 37 30.8 free running processor clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 30.9 programmable clock output controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 30.10 main processor fast startup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538 30.11 main processor startup from embedded flash. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539 30.12 coprocessor sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 30.13 main clock failure detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 0 30.14 slow crystal clock frequency monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 30.15 programming sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 30.16 clock switching details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543 30.17 register write protection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546 30.18 power management controller (pmc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . 547 31. chip identifier (chipid) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 31.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 31.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 31.3 chip identifier (chipid) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577 32. parallel input/output controller (pio) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 32.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 32.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582 32.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583 32.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 4 32.5 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585 32.6 parallel input/output controller (pio) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 593 33. serial peripheral interface (spi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 33.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 33.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 33.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646 33.4 application block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 6 33.5 signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
sam4cp [datasheet] 43051e?atpl?08/14 1066 33.6 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 7 33.7 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648 33.8 serial peripheral interface (spi) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659 34. two-wire interface (twi) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 34.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 34.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 34.3 list of abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676 34.4 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676 34.5 application block diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 6 34.6 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 7 34.7 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 678 34.8 two-wire interface (twi) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 701 35. universal asynchronous receiver transmitter (uart) . . . . . . . . . . . . . . . . . . . . 718 35.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718 35.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718 35.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 718 35.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 9 35.5 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719 35.6 universal asynchronous receiver transmitter (uart) user interface . . . . . . . . . . . . . 726 36. universal synchronous asynchronous receiver transceiver (usart) . . . . . . 738 36.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738 36.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 738 36.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739 36.4 i/o lines description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739 36.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 0 36.6 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 741 36.7 universal synchronous asynchronous receiver transmitter (usart) user interface . 769 37. timer counter (tc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800 37.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800 37.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800 37.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801 37.4 pin name list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802 37.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 2 37.6 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803 37.7 timer counter (tc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 822 38. pulse width modulation controller (pwm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848 38.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848 38.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848 38.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849 38.4 i/o lines description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849 38.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 0 38.6 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850 38.7 pulse width modulation controller (pwm) user interface . . . . . . . . . . . . . . . . . . . . . . . 857 39. segment liquid crystal display controller (slcdc) . . . . . . . . . . . . . . . . . . . . . . 871 39.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871 39.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 871 39.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 872 39.4 i/o lines description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873 39.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 3 39.6 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 875 39.7 waveform specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 86 39.8 segment lcd controller (slcdc) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 887
1067 sam4cp [datasheet] 43051e?atpl?08/14 40. analog-to-digital converter (adc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905 40.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905 40.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905 40.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906 40.4 signal description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906 40.5 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 6 40.6 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908 40.7 register write protection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 917 40.8 analog-to-digital converter (adc) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 918 41. advanced encryption standard (aes) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941 41.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941 41.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 941 41.3 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 1 41.4 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 942 41.5 advanced encryption standard (aes) user interface. . . . . . . . . . . . . . . . . . . . . . . . . . . 953 42. integrity check monitor (icm) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973 42.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973 42.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974 42.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 974 42.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 4 42.5 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 975 42.6 programming the icm for multiple regions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 984 42.7 integrity check monitor (icm) user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 985 43. classical public key cryptography controller (cpkcc) . . . . . . . . . . . . . . . . . . . 999 43.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 999 43.2 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 9 43.3 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 999 44. true random number generator (trng) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000 44.1 description. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000 44.2 embedded characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000 44.3 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000 44.4 product dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1000 44.5 functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 001 44.6 true random number generator (trng) user interface . . . . . . . . . . . . . . . . . . . . . . 1001 45. sam4cp electrical characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 45.1 absolute maximum ratings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 45.2 recommended operating conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1008 45.3 electrical parameters usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009 45.4 i/o characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009 45.5 embedded analog peripherals characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1017 45.6 embedded flash characteristics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1038 45.7 power supply current consumption . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1039 45.8 power on considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1048 46. sam4cp mechanical characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1049 46.1 soldering profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1050 46.2 packaging resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 0 47. marking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1051 48. ordering information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1052 49. errata . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053 49.1 supply controller (supc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053 49.2 parallel input output (pio) controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053
sam4cp [datasheet] 43051e?atpl?08/14 1068 49.3 watchdog (wdt) / reinforced safety watchdog (rswdt) . . . . . . . . . . . . . . . . . . . . . 1053 49.4 enhanced embedded flash controller (eefc). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054 49.5 wait for interrupt (wfi). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 054 49.6 power supply and power control / clock system. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1054 49.7 power management controller (pmc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1055 50. revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1056 table of contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 62
atmel corporation 1600 technology drive, san jose, ca 95110 usa t: (+1)(408) 441.0311 f: (+1)(408) 436.4200 | www.atmel.com ? 2014 atmel corporation. / rev.: 43051e?atpl?08/14 atmel ? , atmel logo and combinations thereof, enabling unlimited possibilities ? , and others are registered trademarks or trademarks of atmel corporation in u.s. and other countries. arm ? , arm connected ? logo, and others are the registered trademarks or trademarks of arm ltd. other terms and product names may be trademarks of others. disclaimer: the information in this document is provided in connection with atmel products. no license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of atmel products. except as set forth in the atmel terms and condition s of sales located on the atmel website, atmel assumes no liability whatsoever and disclaims any express, implied or statutory warranty relating to its product s including, but not limited to, the implied warranty of merchantability, fitness for a particular purpose, or non-infringement. in no event shall a tmel be liable for any direct, indirect, consequential, punitive, special or incidental damages (including, without limitation, damages for loss and p rofits, business interruption, or loss of information) arising out of the use or inability to use this document, even if atmel has been advised of the possibility of such damages. atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. atmel does not make any commitment to update the informati on contained herein. unless specifically provided otherwise, atmel products are not suitable for, and shall not be used in, automotive applications. atmel products are not intended, author ized, or warranted for use as components in applications intended to support or sustain life. safety-critical, military, and automotive applications disclaimer: atmel products are not designed for and will not be used in connection with any applications where the failure of such products would reasonably be expected to result in significant personal injury or death (?safety-critical applications? ) without an atmel officer's specific written consent. safety-critical applications include, without limitation, life support devices and systems, equipment or systems for the operation of nuclear f acilities and weapons systems. atmel products are not designed nor intended for use in military or aerospace applications or environments unless specifically designated by atmel as military-grad e. atmel products are not designed nor intended for use in automotive applications unless specifically designated by atmel as automotive-grade. arm connected logo x x x x x x


▲Up To Search▲   

 
Price & Availability of U3741BM-M3FL

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X